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

[Combobox] Set value if selection is cleared #2307

Merged
merged 1 commit into from
Jul 2, 2024
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
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);
}
Loading