From ee70415c4545e3eec0a30b834e22b24783506188 Mon Sep 17 00:00:00 2001 From: mckaragoz <78308169+mckaragoz@users.noreply.github.com> Date: Fri, 10 Mar 2023 15:19:44 +0300 Subject: [PATCH] Select SearchBox Clearable and Ctrl A Fix --- .../Components/ListExtended/MudListExtended.razor | 2 +- .../ListExtended/MudListExtended.razor.cs | 14 ++++++++++++++ .../SelectExtended/MudSelectExtended.razor | 2 +- .../SelectExtended/MudSelectExtended.razor.cs | 6 ++++++ .../Pages/Examples/SelectExtendedExample6.razor | 6 ++++-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor b/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor index 56f592a5..24bb361c 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor +++ b/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor @@ -33,7 +33,7 @@ } + Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color" AutoFocus="@SearchBoxAutoFocus" Clearable="@SearchBoxClearable" /> @if (MultiSelection && SelectAll && SelectAllPosition == SelectAllPosition.AfterSearchBox && ParentList == null) diff --git a/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs b/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs index 52d3038b..9735e365 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs +++ b/CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs @@ -164,6 +164,13 @@ public Func ToStringFunc [Category(CategoryTypes.List.Behavior)] public bool SearchBoxAutoFocus { get; set; } + /// + /// If true, the search-box has a clear icon. + /// + [Parameter] + [Category(CategoryTypes.List.Behavior)] + public bool SearchBoxClearable { get; set; } + /// /// SearchBox's CSS classes, seperated by space. /// @@ -793,6 +800,13 @@ protected internal async Task SearchBoxHandleKeyDown(KeyboardEventArgs obj) await _searchField.FocusAsync(); StateHasChanged(); break; + case "a": + case "A": + if (obj.CtrlKey == true) + { + await _searchField.SelectAsync(); + } + break; } } diff --git a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor index 48c9a2c6..07f41053 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor +++ b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor @@ -111,7 +111,7 @@ Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle" MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllPosition="@SelectAllPosition" SelectAllText="@SelectAllText" CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer" - ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" ToStringFunc="@ToStringFunc"> + ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" SearchBoxClearable="@SearchBoxClearable" ToStringFunc="@ToStringFunc"> @ChildContent diff --git a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs index 83107ed8..5a28cff3 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs +++ b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs @@ -347,6 +347,12 @@ public bool Dense [Category(CategoryTypes.List.Behavior)] public bool SearchBoxAutoFocus { get; set; } + /// + /// If true, the search-box has a clear icon. + /// + [Parameter] + [Category(CategoryTypes.List.Behavior)] + public bool SearchBoxClearable { get; set; } /// /// If true, prevent scrolling while dropdown is open. diff --git a/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample6.razor b/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample6.razor index 420ac82d..c6bf99af 100644 --- a/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample6.razor +++ b/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample6.razor @@ -1,14 +1,15 @@  - - + + + @@ -16,6 +17,7 @@ @code { bool _multiselection; bool _searchBoxAutoFocus; + bool _searchBoxClearable; private string[] _states = {