Skip to content

Commit e88b589

Browse files
authored
Added SearchBoxAutoFocus to Extended (Select & List), Updated Docs Example. (#116)
* Added SearchBoxAutoFocus Parameter to Extended Components (List, Select) * IconColor should be `AdornmentColor` in MudText component. * Updated Example to use `SearchBoxAutoFocus`.
1 parent 326f680 commit e88b589

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

CodeBeam.MudExtensions/Components/ListExtended/MudListExtended.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<MudListItemExtended T="T" IsFunctional="true" Icon="@SelectAllCheckBoxIcon" IconColor="@Color" Text="@SelectAllText" OverrideMultiSelectionComponent="MultiSelectionComponent.None" OnClick="@(() => SelectAllItems(_allSelected))" OnClickHandlerPreventDefault="true" Dense="@Dense" Class="mb-2" />
1212
<MudDivider />
1313
}
14-
14+
1515
@if (ItemCollection != null)
1616
{
1717
@if (SearchBox == true)
1818
{
1919
<MudListSubheaderExtended T="T" Style="position: sticky; top: -12px; background-color: var(--mud-palette-background); z-index: 10">
2020
<div @onkeydown:stopPropagation>
2121
<MudTextField @bind-Value="@_searchString" Class="@ClassSearchBox" OnKeyUp="@(() => UpdateSelectedStyles())" Immediate="true" Variant="Variant.Outlined" Margin="Margin.Dense"
22-
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" IconColor="Color" />
22+
Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color" AutoFocus="@SearchBoxAutoFocus" />
2323
</div>
2424

2525
</MudListSubheaderExtended>

CodeBeam.MudExtensions/Components/ListExtended/MudListExtended.razor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ public Func<T, string> ToStringFunc
142142
[Category(CategoryTypes.List.Behavior)]
143143
public bool SearchBox { get; set; }
144144

145+
/// <summary>
146+
/// If true, the search-box will be focused when the dropdown is opened.
147+
/// </summary>
148+
[Parameter]
149+
[Category(CategoryTypes.List.Behavior)]
150+
public bool SearchBoxAutoFocus { get; set; }
151+
145152
/// <summary>
146153
/// SearchBox's CSS classes, seperated by space.
147154
/// </summary>

CodeBeam.MudExtensions/Components/SelectExtended/MudSelectExtended.razor

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Disabled="@Disabled" ReadOnly="true" Error="@Error" ErrorId="@ErrorId"
2626
Clearable="@Clearable" OnClearButtonClick="(async (e) => await SelectClearButtonClickHandlerAsync(e))"
2727
@attributes="UserAttributes" OnBlur="@OnLostFocus">
28-
28+
2929
<AdornmentEnd>
3030
<MudIcon Icon="@_currentIcon" Color="@AdornmentColor" Size="@IconSize" @onclick="OnAdornmentClick" />
3131
</AdornmentEnd>
@@ -43,7 +43,7 @@
4343
{
4444
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
4545
}
46-
46+
4747
<MudRender>@GetSelectTextPresenter()</MudRender>
4848
}
4949
else if (ValuePresenter == ValuePresenter.Chip)
@@ -65,7 +65,7 @@
6565
if (SelectedListItem == null)
6666
{
6767
<MudText Typo="Typo.body1" Class="mud-text-secondary">@Placeholder</MudText>
68-
68+
6969
}
7070
else if (ItemTemplate != null)
7171
{
@@ -102,12 +102,12 @@
102102
Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle"
103103
MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllText="@SelectAllText"
104104
CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer"
105-
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" ToStringFunc="@ToStringFunc">
105+
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" ToStringFunc="@ToStringFunc">
106106
@ChildContent
107107
</MudListExtended>
108108
</CascadingValue>
109109
</MudPopover>
110-
</InputContent>
110+
</InputContent>
111111
</MudInputControl>
112112
</div>
113113

@@ -120,4 +120,4 @@
120120

121121
</CascadingValue>
122122
<!-- mousedown instead of click needed to close the menu before OnLostFocus runs -->
123-
<MudOverlay Visible="_isOpen" @onmousedown="@(() => CloseMenu())" LockScroll="@LockScroll" />
123+
<MudOverlay Visible="_isOpen" @onmousedown="@(() => CloseMenu())" LockScroll="@LockScroll" />

CodeBeam.MudExtensions/Components/SelectExtended/MudSelectExtended.razor.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,14 @@ public bool Dense
303303
[Category(CategoryTypes.List.Behavior)]
304304
public bool SearchBox { get; set; }
305305

306+
/// <summary>
307+
/// If true, the search-box will be focused when the dropdown is opened.
308+
/// </summary>
309+
[Parameter]
310+
[Category(CategoryTypes.List.Behavior)]
311+
public bool SearchBoxAutoFocus { get; set; }
312+
313+
306314
/// <summary>
307315
/// If true, prevent scrolling while dropdown is open.
308316
/// </summary>
@@ -461,7 +469,7 @@ public IEnumerable<T> SelectedValues
461469
SetValueAsync(_selectedValues.LastOrDefault(), false).AndForget();
462470
UpdateTextPropertyAsync(false).AndForget();
463471
}
464-
472+
465473
SelectedValuesChanged.InvokeAsync(new HashSet<T>(SelectedValues, _comparer)).AndForget();
466474
_selectedValuesSetterStarted = false;
467475
//Console.WriteLine("SelectedValues setter ended");

ComponentViewer.Docs/Pages/Examples/SelectExtendedExample6.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11

22
<MudGrid>
33
<MudItem xs="12" sm="8">
4-
<MudSelectExtended MultiSelection="@_multiselection" ItemCollection="_states" SearchBox="true" T="string" Label="US States" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" />
4+
<MudSelectExtended MultiSelection="@_multiselection" ItemCollection="_states" SearchBox="true" SearchBoxAutoFocus="@_searchBoxAutoFocus" T="string" Label="US States" AnchorOrigin="Origin.BottomCenter" Variant="Variant.Outlined" />
55
</MudItem>
66

77
<MudItem xs="12" sm="4">
88
<MudStack>
99
<MudSwitchM3 @bind-Checked="_multiselection" Color="Color.Primary" Label="MultiSelection" />
10+
<MudSwitchM3 @bind-Checked="_searchBoxAutoFocus" Color="Color.Primary" Label="AutoFocus (SearchBox)" />
1011
</MudStack>
1112
</MudItem>
1213
</MudGrid>
1314

1415
@code {
1516
bool _multiselection;
17+
bool _searchBoxAutoFocus;
1618

1719
private string[] _states =
1820
{
@@ -32,4 +34,4 @@
3234
"Washington", "West Virginia", "Wisconsin", "Wyoming",
3335
};
3436

35-
}
37+
}

0 commit comments

Comments
 (0)