From 0c4932e52667585fd517fc6b65b0dc16df2dae0f Mon Sep 17 00:00:00 2001 From: mckaragoz <78308169+mckaragoz@users.noreply.github.com> Date: Tue, 25 Apr 2023 21:49:41 +0300 Subject: [PATCH 1/2] Some Select Bug Fixes --- .../SelectExtended/MudSelectExtended.razor | 192 +++++++++--------- .../SelectExtended/MudSelectExtended.razor.cs | 14 +- .../Examples/SelectExtendedExample5.razor | 30 +++ 3 files changed, 141 insertions(+), 95 deletions(-) diff --git a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor index 5ffbb49f..4a81c4d6 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor +++ b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor @@ -5,137 +5,147 @@ -
- - - +
+ + + - - - + + + - - @if (ValuePresenter == ValuePresenter.Chip) - { - - @foreach (var item in Items?.Where(x => SelectedValues.Contains(x.Value)) ?? new List>()) - { - - } - - } - - - -
- @if (Strict && !IsValueInList) + + @if (ValuePresenter == ValuePresenter.Chip) { - //Show nothing - @Placeholder + + @if (ItemCollection != null) + { + foreach (var item in ItemCollection.Where(x => SelectedValues.Contains(x))) + { + + } + } + else + { + foreach (var item in Items?.Where(x => SelectedValues.Contains(x.Value)) ?? new List>()) + { + + } + } + } - else if (ValuePresenter == ValuePresenter.Text) - { - @if (string.IsNullOrEmpty(Text)) - { - @Placeholder - } + - @GetSelectTextPresenter() - } - else if (ValuePresenter == ValuePresenter.Chip) - { - if (SelectedValues == null || !SelectedValues.Any()) + +
+ @if (Strict && !IsValueInList) { + //Show nothing @Placeholder } - else - { - @*Chips show under DataVisualiser RenderFragment*@ - } - } - else if (ValuePresenter == ValuePresenter.ItemContent) - { - if (SelectedListItem == null) + else if (ValuePresenter == ValuePresenter.Text) { - @Placeholder + @if (string.IsNullOrEmpty(Text)) + { + @Placeholder + } + @GetSelectTextPresenter() } - else if (ItemTemplate != null) + else if (ValuePresenter == ValuePresenter.Chip) { - if (SelectedListItem != null && SelectedListItem.Value != null) + if (SelectedValues == null || !SelectedValues.Any()) { - @ItemTemplate(SelectedListItem) + @Placeholder } - else if (!string.IsNullOrEmpty(Placeholder)) + else { - @Placeholder + @*Chips show under DataVisualiser RenderFragment*@ } } - else if (SelectedListItem.ChildContent != null) - { - @SelectedListItem.ChildContent - } - else + else if (ValuePresenter == ValuePresenter.ItemContent) { - @if (string.IsNullOrEmpty(Text)) + if (SelectedListItem == null) { @Placeholder + } + else if (ItemTemplate != null) + { + if (SelectedListItem != null && SelectedListItem.Value != null) + { + @ItemTemplate(SelectedListItem) + } + else if (!string.IsNullOrEmpty(Placeholder)) + { + @Placeholder + } + } + else if (SelectedListItem.ChildContent != null) + { + @SelectedListItem.ChildContent + } + else + { + @if (string.IsNullOrEmpty(Text)) + { + @Placeholder + } - @GetSelectTextPresenter() + @GetSelectTextPresenter() + } } - } -
-
- +
+
+
- - - @ChildContent - - - -
-
-
+ + + @ChildContent + + + +
+
+
- @*To Be Discussed as Second ShadowItems: Needed to render directly into select to has initial values*@ + @*To Be Discussed as Second ShadowItems: Needed to render directly into select to has initial values*@ -
- +
+ - @ChildContent - + @ChildContent + -
+
@*Shadow select items for IsValueInList and CanRenderValue*@ - @ChildContent - - + @ChildContent +
+ + - diff --git a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs index d8e89d63..baa400b8 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs +++ b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs @@ -56,6 +56,7 @@ public MudSelectExtended() .Build(); private string _elementId = "select_" + Guid.NewGuid().ToString().Substring(0, 8); + private string _popoverId = "selectpopover_" + Guid.NewGuid().ToString().Substring(0, 8); /// /// User class names for the input, separated by space @@ -879,7 +880,7 @@ public async Task OpenMenu() //disable escape propagation: if selectmenu is open, only the select popover should close and underlying components should not handle escape key await _keyInterceptor.UpdateKey(new() { Key = "Escape", StopDown = "Key+none" }); - + await ScrollToMiddleAsync(GetSelectedItem()); await OnOpen.InvokeAsync(); } @@ -966,9 +967,9 @@ public override async Task ForceUpdate() } } - public void BeginValidatePublic() + public async Task BeginValidatePublic() { - BeginValidate(); + await BeginValidateAsync(); } protected internal bool Add(MudSelectItemExtended item) @@ -1108,7 +1109,12 @@ protected override bool HasValue(T value) protected async Task ChipClosed(MudChip chip) { - SelectedValues = SelectedValues.Where(x => Converter.Set(x)?.ToString() != chip.Value?.ToString()); + if (chip == null || SelectedValues == null) + { + return; + } + //SelectedValues = SelectedValues.Where(x => Converter.Set(x)?.ToString() != chip.Value?.ToString()); + SelectedValues = SelectedValues.Where(x => x.Equals(chip.Value) == false); await SelectedValuesChanged.InvokeAsync(SelectedValues); } } diff --git a/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample5.razor b/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample5.razor index bb50aca1..464265ab 100644 --- a/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample5.razor +++ b/ComponentViewer.Docs/Pages/Examples/SelectExtendedExample5.razor @@ -16,6 +16,23 @@ } + + + + + @@ -110,4 +127,17 @@ _valuePresenter = ValuePresenter.Text; } } + + public record TestValue(int Number, string Value); + + List? TestValues { get; set; } + IEnumerable SelectedTsSearchBoxItems { get; set; } + + protected override void OnInitialized() + { + TestValues = Enumerable.Range(0, 1000) + .Select(n => new TestValue(n, $"Value-{n.ToString("0000")}")) + .ToList(); + base.OnInitialized(); + } } \ No newline at end of file From aca5b963303f8db0af274625db02468f047f6750 Mon Sep 17 00:00:00 2001 From: mckaragoz <78308169+mckaragoz@users.noreply.github.com> Date: Tue, 25 Apr 2023 21:50:16 +0300 Subject: [PATCH 2/2] Fix A Line --- .../Components/SelectExtended/MudSelectExtended.razor.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs index baa400b8..2d49a47e 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs +++ b/CodeBeam.MudBlazor.Extensions/Components/SelectExtended/MudSelectExtended.razor.cs @@ -880,7 +880,6 @@ public async Task OpenMenu() //disable escape propagation: if selectmenu is open, only the select popover should close and underlying components should not handle escape key await _keyInterceptor.UpdateKey(new() { Key = "Escape", StopDown = "Key+none" }); - await ScrollToMiddleAsync(GetSelectedItem()); await OnOpen.InvokeAsync(); }