Skip to content

Commit

Permalink
Refined HandleOnBlur
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Jangli authored and Jeffrey Jangli committed Oct 22, 2023
1 parent a5314ae commit 1379d3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ protected async Task SyncMultiselectionValues(bool singleToMultiselection)
}
else
{
if (Value is string && string.IsNullOrEmpty(Converter.Set(Value)))
if (Value is string && string.IsNullOrWhiteSpace(Converter.Set(Value)))
{
SelectedValues = new HashSet<T>();
}
Expand Down Expand Up @@ -601,7 +601,7 @@ protected Task UpdateDataVisualiserTextAsync()
var item = Items.FirstOrDefault(x => x != null && (x.Value == null ? val == null : Comparer != null ? Comparer.Equals(x.Value, val) : x.Value.Equals(val)));
if (item != null)
{
textList.Add(!string.IsNullOrEmpty(item.Text) ? item.Text : Converter.Set(item.Value));
textList.Add(!string.IsNullOrWhiteSpace(item.Text) ? item.Text : Converter.Set(item.Value));
}
}
}
Expand Down Expand Up @@ -632,7 +632,7 @@ protected Task UpdateDataVisualiserTextAsync()
var item = Items.FirstOrDefault(x => Value == null ? x.Value == null : Comparer != null ? Comparer.Equals(Value, x.Value) : Value.Equals(x.Value));
_dataVisualiserText = item is null
? Converter.Set(Value)
: (!string.IsNullOrEmpty(item.Text) ? item.Text : Converter.Set(item.Value));
: (!string.IsNullOrWhiteSpace(item.Text) ? item.Text : Converter.Set(item.Value));

return Task.CompletedTask;
}
Expand Down Expand Up @@ -934,16 +934,13 @@ protected internal async Task HandleOnBlur(FocusEventArgs obj)
// Restore the previous selected item, if any.
if (Value is not null)
{
if (!Editable)
{
item = Items.FirstOrDefault(x => x.Value.Equals(Value));
if (item is not null)
await ToggleOption(item, true);

// Remove non-matching search string.
else
await Clear();
}
item = Items.FirstOrDefault(x => x.Value.Equals(Value));
if (item is not null)
await ToggleOption(item, true);

// Remove non-matching search string.
else
await Clear();
}

// There was no previous selected item. Remove non-matching search string.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public partial class MudComboBoxItem<T> : MudBaseSelectItem, IDisposable
.Build();

protected string HighlighterClassname => new CssBuilder()
.AddClass("mud-combobox-highlighter", MudComboBox is not null && MudComboBox.Highlight && string.IsNullOrEmpty(MudComboBox.HighlightClass))
.AddClass("mud-combobox-highlighter", MudComboBox is not null && MudComboBox.Highlight && string.IsNullOrWhiteSpace(MudComboBox.HighlightClass))
.AddClass(MudComboBox?.HighlightClass, MudComboBox is not null && MudComboBox.Highlight)
.Build();

Expand Down Expand Up @@ -97,8 +97,8 @@ protected string DisplayString
}

if (converter == null)
return $"{(string.IsNullOrEmpty(Text) ? Value : Text)}";
return !string.IsNullOrEmpty(Text) ? Text : converter.Set(Value);
return $"{(string.IsNullOrWhiteSpace(Text) ? Value : Text)}";
return !string.IsNullOrWhiteSpace(Text) ? Text : converter.Set(Value);
}
}

Expand Down Expand Up @@ -158,7 +158,7 @@ protected bool IsEligible()
return true;
}

if (string.IsNullOrEmpty(MudComboBox._searchString))
if (string.IsNullOrWhiteSpace(MudComboBox._searchString))
{
return true;
}
Expand All @@ -168,7 +168,7 @@ protected bool IsEligible()
return MudComboBox.SearchFunc.Invoke(Value, Text, MudComboBox.GetSearchString());
}

if (string.IsNullOrEmpty(Text) == false)
if (string.IsNullOrWhiteSpace(Text) == false)
{
if (Text.Contains(MudComboBox._searchString ?? string.Empty, StringComparison.CurrentCultureIgnoreCase))
{
Expand Down

0 comments on commit 1379d3e

Please sign in to comment.