Skip to content
Merged

Fixes #304

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -581,7 +581,7 @@ protected Task UpdateDataVisualiserTextAsync()
{
if (MultiSelectionTextFunc != null)
{
if (SelectedValues.Count() == 0)
if (!SelectedValues.Any())
{
_dataVisualiserText = null;
return Task.CompletedTask;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion ComponentViewer.Docs/Pages/Examples/ComboboxExample8.razor
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down