Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/Core/Components/DateTime/FluentDatePicker.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,15 @@ protected async Task OnSelectedDateAsync(DateTime? value)
{
Opened = false;

var updatedValue = Value?.TimeOfDay != TimeSpan.Zero
? (value ?? DateTime.MinValue).Date + Value?.TimeOfDay
: value;
DateTime? updatedValue = value;

if (Value is not null && value is not null)
{
updatedValue = Value?.TimeOfDay != TimeSpan.Zero
? value?.Date + Value?.TimeOfDay
: value;
}

await OnSelectedDateHandlerAsync(updatedValue);
}

Expand Down
23 changes: 23 additions & 0 deletions tests/Core/DateTime/FluentDatePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,27 @@ public void FluentCalendar_DisabledDate()
// Assert
calendar.Verify();
}

[Fact]
public void FluentDatePicker_ChangeValueWhenDefaultIsNull()
{
// Arrange
using var ctx = new TestContext();
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
ctx.Services.AddSingleton(LibraryConfiguration);

// Act
var picker = ctx.RenderComponent<FluentDatePicker>(parameters =>
{
parameters.Add(p => p.Value, null);
});

var textField = picker.Find("fluent-text-field");

// Set a new date value
textField.Change("2022-03-12");

// Assert
Assert.Equal(System.DateTime.Parse("2022-03-12"), picker.Instance.Value);
}
}