Skip to content

Commit 19777b1

Browse files
authored
Add a search string change event (#338)
1 parent 7ccb9f6 commit 19777b1

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
{
3333
<MudCheckBox CheckedIcon="@SelectAllCheckBoxIcon" Color="@Color" @bind-Checked="_allSelected" @onclick="() => SelectAllItems(_allSelected)" Dense="true" />
3434
}
35-
<MudTextField @ref="_searchField" @bind-Value="@_searchString" Class="@ClassSearchBox" Placeholder="@SearchBoxPlaceholder" OnKeyDown="SearchBoxHandleKeyDown" OnKeyUp="@(() => UpdateSelectedStyles())" OnClearButtonClick="@(() => UpdateSelectedStyles())" Immediate="true" Variant="SearchBoxVariant" Margin="Margin.Dense"
35+
<MudTextField T="string" @ref="_searchField" ValueChanged="SearchChanged" Class="@ClassSearchBox" Placeholder="@SearchBoxPlaceholder" OnKeyDown="SearchBoxHandleKeyDown" OnKeyUp="@(() => UpdateSelectedStyles())" OnClearButtonClick="@(() => UpdateSelectedStyles())" Immediate="true" Variant="SearchBoxVariant" Margin="Margin.Dense"
3636
Adornment="SearchBoxAdornment" AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color" AutoFocus="@SearchBoxAutoFocus" Clearable="@SearchBoxClearable" />
3737
</div>
3838
</MudListSubheaderExtended>

CodeBeam.MudBlazor.Extensions/Components/ListExtended/MudListExtended.razor.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
using System.Data;
2-
using Microsoft.AspNetCore.Components;
1+
using Microsoft.AspNetCore.Components;
32
using Microsoft.AspNetCore.Components.Web;
43
using MudBlazor;
54
using MudBlazor.Services;
65
using MudBlazor.Utilities;
76
using MudExtensions.Enums;
87
using MudExtensions.Services;
9-
using static MudBlazor.CategoryTypes;
10-
using static MudBlazor.Colors;
8+
using System.Data;
119

1210
namespace MudExtensions
1311
{
@@ -199,6 +197,11 @@ public Func<T, string> ToStringFunc
199197
[Category(CategoryTypes.List.Behavior)]
200198
public string SearchBoxPlaceholder { get; set; }
201199

200+
/// <summary>
201+
/// Fired when the search value changes.
202+
/// </summary>
203+
[Parameter] public EventCallback<string> OnSearchStringChange { get; set; }
204+
202205
/// <summary>
203206
/// Allows virtualization. Only work if ItemCollection parameter is not null.
204207
/// </summary>
@@ -929,6 +932,12 @@ protected void HandleOnScroll()
929932
}
930933
}
931934

935+
protected async Task SearchChanged(string searchString)
936+
{
937+
_searchString = searchString;
938+
await OnSearchStringChange.InvokeAsync(searchString);
939+
}
940+
932941
#endregion
933942

934943

CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@
109109
Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle"
110110
MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllPosition="@SelectAllPosition" SelectAllText="@SelectAllText"
111111
CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer"
112-
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" SearchBoxClearable="@SearchBoxClearable" SearchBoxVariant="@SearchBoxVariant" SearchBoxAdornment="SearchBoxAdornment" ToStringFunc="@ToStringFunc">
112+
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder"
113+
SearchBoxClearable="@SearchBoxClearable" SearchBoxVariant="@SearchBoxVariant" SearchBoxAdornment="SearchBoxAdornment" ToStringFunc="@ToStringFunc" OnSearchStringChange="@OnSearchStringChange">
113114
@ChildContent
114115
</MudListExtended>
115116
</CascadingValue>
@@ -126,7 +127,8 @@
126127
Clickable="true" Color="@Color" Dense="@Dense" ItemCollection="@ItemCollection" Virtualize="@Virtualize" DisablePadding="@DisablePopoverPadding" DisableSelectedItemStyle="@DisableSelectedItemStyle"
127128
MultiSelection="@MultiSelection" MultiSelectionComponent="@MultiSelectionComponent" MultiSelectionAlign="@MultiSelectionAlign" SelectAll="@SelectAll" SelectAllPosition="@SelectAllPosition" SelectAllText="@SelectAllText"
128129
CheckedIcon="@CheckedIcon" UncheckedIcon="@UncheckedIcon" IndeterminateIcon="@IndeterminateIcon" SelectValueOnTab="@SelectValueOnTab" Comparer="@Comparer"
129-
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder" SearchBoxClearable="@SearchBoxClearable" SearchBoxVariant="@SearchBoxVariant" SearchBoxAdornment="SearchBoxAdornment" ToStringFunc="@ToStringFunc">
130+
ItemTemplate="@ItemTemplate" ItemSelectedTemplate="@ItemSelectedTemplate" ItemDisabledTemplate="@ItemDisabledTemplate" SearchBox="@SearchBox" SearchBoxAutoFocus="@SearchBoxAutoFocus" SearchFunc="@SearchFunc" SearchBoxPlaceholder="@SearchBoxPlaceholder"
131+
SearchBoxClearable="@SearchBoxClearable" SearchBoxVariant="@SearchBoxVariant" SearchBoxAdornment="SearchBoxAdornment" ToStringFunc="@ToStringFunc" OnSearchStringChange="@OnSearchStringChange">
130132
@ChildContent
131133
</MudListExtended>
132134
</CascadingValue>

CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore.Components;
1+
using Microsoft.AspNetCore.Components;
72
using Microsoft.AspNetCore.Components.Web;
83
using MudBlazor;
94
using MudBlazor.Services;
105
using MudBlazor.Utilities;
116
using MudBlazor.Utilities.Exceptions;
127
using MudExtensions.Enums;
13-
using MudExtensions.Extensions;
14-
using static MudBlazor.CategoryTypes;
8+
using System.Diagnostics.CodeAnalysis;
159

1610
namespace MudExtensions
1711
{
@@ -378,6 +372,13 @@ public bool Dense
378372
[Category(CategoryTypes.List.Behavior)]
379373
public Adornment SearchBoxAdornment { get; set; } = Adornment.End;
380374

375+
/// <summary>
376+
/// Fired when the search value changes.
377+
/// </summary>
378+
[Parameter]
379+
[Category(CategoryTypes.FormComponent.Behavior)]
380+
public EventCallback<string> OnSearchStringChange { get; set; }
381+
381382
/// <summary>
382383
/// If true, prevent scrolling while dropdown is open.
383384
/// </summary>
@@ -612,7 +613,7 @@ protected override Task UpdateValuePropertyAsync(bool updateText)
612613
{
613614
// For MultiSelection of non-string T's we don't update the Value!!!
614615
//if (typeof(T) == typeof(string) || !MultiSelection)
615-
base.UpdateValuePropertyAsync(updateText).AndForget();
616+
base.UpdateValuePropertyAsync(updateText).AndForget();
616617
return Task.CompletedTask;
617618
}
618619

@@ -971,7 +972,7 @@ public async Task SelectOption(object obj)
971972

972973
//await SelectedValuesChanged.InvokeAsync(SelectedValues);
973974
//if (MultiSelection && typeof(T) == typeof(string))
974-
//await SetValueAsync((T)(object)Text, updateText: false);
975+
//await SetValueAsync((T)(object)Text, updateText: false);
975976
await InvokeAsync(StateHasChanged);
976977
}
977978

@@ -1136,7 +1137,7 @@ protected async Task ChipClosed(MudChip chip)
11361137
return;
11371138
}
11381139
//SelectedValues = SelectedValues.Where(x => Converter.Set(x)?.ToString() != chip.Value?.ToString());
1139-
SelectedValues = SelectedValues.Where(x => x.Equals(chip.Value) == false);
1140+
SelectedValues = SelectedValues.Where(x => x.Equals(chip.Value) == false);
11401141
await SelectedValuesChanged.InvokeAsync(SelectedValues);
11411142
}
11421143
}

0 commit comments

Comments
 (0)