Skip to content

Commit

Permalink
Combobox: update value if selection is cleared
Browse files Browse the repository at this point in the history
  • Loading branch information
AI\jvermeyl committed Jul 2, 2024
1 parent 8f9a21e commit 93f1479
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Core/Components/List/FluentCombobox.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<style>#myComponent::part(listbox) { z-index: 9995 }</style>
<fluent-combobox id="xxx" current-value="" position="below" blazor:onchange="1" blazor:elementreference="">
<fluent-option id="xxx" value="Contoso" blazor:onclick="2" blazor:elementreference="">Contoso</fluent-option>
</fluent-combobox>
20 changes: 20 additions & 0 deletions tests/Core/List/FluentComboboxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<FluentCombobox<Customer>>(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);
}

0 comments on commit 93f1479

Please sign in to comment.