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
9 changes: 8 additions & 1 deletion src/Core/Components/List/FluentAutocomplete.razor
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@

if (Multiple == false)
{
<FluentLabel tabindex="0" aria-label="@GetOptionText(item)" role="checkbox" aria-checked="true">@text</FluentLabel>
<FluentLabel Id="@($"{Id}-single")"
tabindex="0"
aria-label="@GetOptionText(item)"
role="checkbox"
aria-checked="true"
@onkeydown="@(e => e.Code == "Delete" || e.Code == "Backspace" ? RemoveSelectedItemAsync(item) : Task.CompletedTask)">
@text
</FluentLabel>
}
else if (ReadOnly || Disabled)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Core/Components/List/FluentAutocomplete.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public async Task InvokeOptionsSearchAsync()
Items = args.Items?.Take(MaximumOptionsSearch);

SelectableItem = Items != null
? Items.FirstOrDefault()
? Items.FirstOrDefault(i => OptionDisabled is null ? true : OptionDisabled.Invoke(i) == false)
: default;

if (VirtualizationContainer != null)
Expand Down Expand Up @@ -558,6 +558,13 @@ protected override async Task OnSelectedItemChangedHandlerAsync(TOption? item)
await RaiseValueTextChangedAsync(ValueText);

await base.OnSelectedItemChangedHandlerAsync(item);

// In Single mode, set the focus on the input field
if (!Multiple && Module != null)
{
await Module.InvokeVoidAsync("focusOn", $"{Id}-single");
}

await DisplayLastSelectedItemAsync();

if (MustBeClosed())
Expand Down
14 changes: 14 additions & 0 deletions src/Core/Components/List/ListComponentBase.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,14 @@ protected virtual async Task OnSelectedItemChangedHandlerAsync(TOption? item)
InternalValue = GetOptionValue(item);
await RaiseChangedEventsAsync();
}

// For Autocomplete, allow to unselect the item if it is already selected
else if (this is FluentAutocomplete<TOption>)
{
SelectedOption = default;
InternalValue = GetOptionValue(default);
await RaiseChangedEventsAsync();
}
}
}

Expand Down Expand Up @@ -632,6 +640,12 @@ protected virtual bool RemoveSelectedItem(TOption? item)
return false;
}

if (this is FluentAutocomplete<TOption> && SelectedOption is not null)
{
SelectedOption = default;
InternalValue = GetOptionValue(default);
}

return _selectedOptions.Remove(item);
}

Expand Down
Loading