diff --git a/src/Core/Components/List/FluentCombobox.razor.cs b/src/Core/Components/List/FluentCombobox.razor.cs index 6b163aa025..360ccc259e 100644 --- a/src/Core/Components/List/FluentCombobox.razor.cs +++ b/src/Core/Components/List/FluentCombobox.razor.cs @@ -111,8 +111,8 @@ public override async Task SetParametersAsync(ParameterView parameters) // Sync Value from selected option. // If it is null, we set it to the default value so the attribute is not deleted & the webcomponents don't throw an exception - var value = GetOptionValue(_currentSelectedOption);// ?? string.Empty; - if (value is not null && Value != value) + var value = GetOptionValue(_currentSelectedOption) ?? string.Empty; + if (Value != value) { Value = value; await ValueChanged.InvokeAsync(Value); diff --git a/tests/Core/List/FluentComboboxTests.FluentCombobox_ClearSelection.verified.html b/tests/Core/List/FluentComboboxTests.FluentCombobox_ClearSelection.verified.html new file mode 100644 index 0000000000..28af553a08 --- /dev/null +++ b/tests/Core/List/FluentComboboxTests.FluentCombobox_ClearSelection.verified.html @@ -0,0 +1,5 @@ + + + + Contoso + \ No newline at end of file diff --git a/tests/Core/List/FluentComboboxTests.cs b/tests/Core/List/FluentComboboxTests.cs index 716f6e6713..19019dd9bf 100644 --- a/tests/Core/List/FluentComboboxTests.cs +++ b/tests/Core/List/FluentComboboxTests.cs @@ -49,5 +49,25 @@ public void FluentCombobox_NameAttribute() cut.Verify(); } + [Fact] + public void FluentCombobox_ClearSelection() + { + // Arrange + var customer = new Customer(1, "Contoso"); + var cut = TestContext.RenderComponent>(parameters => + { + parameters.Add(p => p.Id, "myComponent"); + parameters.Add(p => p.Items, [customer]); + parameters.Add(p => p.OptionText, customer => customer.Name); + parameters.Add(p => p.SelectedOption, customer); + }); + + //Act + cut.SetParametersAndRender(parameters => parameters.Add(p => p.SelectedOption, null)); + + // Assert + cut.Verify(); + } + private record Customer(int Id, string Name); }