From 027626dc91f1d63ba15205bb1a07b01795d428f1 Mon Sep 17 00:00:00 2001 From: Jeffrey Jangli Date: Wed, 18 Oct 2023 10:46:31 +0200 Subject: [PATCH] Fixes --- .../Components/ComboBox/MudComboBox.razor.cs | 54 +++++++++++-------- .../Pages/Examples/ComboboxExample8.razor | 2 +- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs b/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs index 3c04e259..4dcccf8a 100644 --- a/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs +++ b/CodeBeam.MudBlazor.Extensions/Components/ComboBox/MudComboBox.razor.cs @@ -58,7 +58,7 @@ public MudComboBox() new StyleBuilder() .AddStyle("height: auto") .AddStyle("min-height: 1.1876em") - .AddStyle("display", "inline", Value != null || SelectedValues.Count() != 0) + .AddStyle("display", "inline", Value != null || SelectedValues.Any()) .Build(); private string _elementId = "combobox_" + Guid.NewGuid().ToString().Substring(0, 8); @@ -581,7 +581,7 @@ protected Task UpdateDataVisualiserTextAsync() { if (MultiSelectionTextFunc != null) { - if (SelectedValues.Count() == 0) + if (!SelectedValues.Any()) { _dataVisualiserText = null; return Task.CompletedTask; @@ -685,7 +685,8 @@ protected override async Task OnParametersSetAsync() else { DeselectAllItems(); - Items.FirstOrDefault(x => x.Value.Equals(Value)).Selected = true; + if (Value is not null) + Items.FirstOrDefault(x => x.Value.Equals(Value)).Selected = true; } } if ((Value == null && _oldValue != null) || (Value != null && Value.Equals(_oldValue) == false)) @@ -1191,7 +1192,7 @@ protected void UpdateIcon() protected override bool HasValue(T value) { if (MultiSelection) - return SelectedValues?.Count() > 0; + return SelectedValues.Any(); else return base.HasValue(value); } @@ -1236,16 +1237,16 @@ protected async Task SelectAllItems() protected bool? GetAllSelectedState() { - if (MultiSelection == true && SelectedValues.Count() == Items.Count) + if (MultiSelection) { - return true; - } + var count = SelectedValues.Count(); + if (count == 0) + return false; - if (MultiSelection == true && SelectedValues.Count() == 0) - { - return false; - } + if (count == Items.Count) + return true; + } return null; } @@ -1279,16 +1280,20 @@ protected int GetActiveItemIndex() protected int GetActiveProperItemIndex() { var properItems = GetEligibleAndNonDisabledItems(); - if (_lastActivatedItem == null) - { - var a = properItems.FindIndex(x => x.Active == true); - return a; - } - else + if (properItems.Any()) { - var a = properItems.FindIndex(x => _lastActivatedItem.Value == null ? x.Value == null : Comparer != null ? Comparer.Equals(_lastActivatedItem.Value, x.Value) : _lastActivatedItem.Value.Equals(x.Value)); - return a; + if (_lastActivatedItem == null) + { + var a = properItems.FindIndex(x => x.Active == true); + return a; + } + else + { + var a = properItems.FindIndex(x => _lastActivatedItem.Value == null ? x.Value == null : Comparer != null ? Comparer.Equals(_lastActivatedItem.Value, x.Value) : _lastActivatedItem.Value.Equals(x.Value)); + return a; + } } + return -1; } protected T GetActiveItemValue() @@ -1339,7 +1344,7 @@ public async Task ActiveFirstItem(string startChar = null) } // find first item that starts with the letter - var possibleItems = Items.Where(x => (x.Text ?? Converter.Set(x.Value) ?? "").StartsWith(startChar, StringComparison.CurrentCultureIgnoreCase)).ToList(); + var possibleItems = Items.Where(x => (x.Text ?? Converter.Set(x.Value) ?? "").StartsWith(startChar, StringComparison.OrdinalIgnoreCase)).ToList(); if (possibleItems == null || !possibleItems.Any()) { if (_lastActivatedItem == null) @@ -1404,8 +1409,13 @@ public async Task ActiveLastItem() } DeactiveAllItems(); var properItems = GetEligibleAndNonDisabledItems(); - properItems.Last().SetActive(true); - _lastActivatedItem = properItems.Last(); + if (properItems.Any()) + { + properItems.Last().SetActive(true); + _lastActivatedItem = properItems.Last(); + } + else + _lastActivatedItem = null; await ScrollToMiddleAsync(_lastActivatedItem); } diff --git a/ComponentViewer.Docs/Pages/Examples/ComboboxExample8.razor b/ComponentViewer.Docs/Pages/Examples/ComboboxExample8.razor index 492453b0..b36e2f37 100644 --- a/ComponentViewer.Docs/Pages/Examples/ComboboxExample8.razor +++ b/ComponentViewer.Docs/Pages/Examples/ComboboxExample8.razor @@ -27,7 +27,7 @@ private bool SearchStartWith(string value, string text, string searchString) { - if (value.StartsWith(searchString, StringComparison.CurrentCultureIgnoreCase)) + if (value.StartsWith(searchString, StringComparison.OrdinalIgnoreCase)) { return true; }