Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TimePicker] Add null check for empty string #2245

Merged
merged 10 commits into from
Jun 24, 2024
2 changes: 1 addition & 1 deletion src/Core/Components/DateTime/FluentTimePicker.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override bool TryParseValueFromString(string? value, out DateTime? res
}
else
{
result = Value?.Date;
result = string.IsNullOrWhiteSpace(value) ? null : Value?.Date;
dvoituron marked this conversation as resolved.
Show resolved Hide resolved
}

validationErrorMessage = null;
Expand Down
13 changes: 13 additions & 0 deletions tests/Core/DateTime/FluentTimePickerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public void FluentTimePicker_TryParseValueFromString(string? value, string? time
}
}

[Fact]
public void FluentTimePicker_EmptyStringToNull()
vnbaaij marked this conversation as resolved.
Show resolved Hide resolved
{
// Arrange
var picker = new TestTimePicker();

// Act
var _ = picker.CallTryParseValueFromString(string.Empty, out var resultDate, out var _);

// Assert
Assert.Null(resultDate);
}

// Temporary class to expose protected method
private class TestTimePicker : FluentTimePicker
{
Expand Down
Loading