@@ -58,7 +58,7 @@ public MudComboBox()
5858 new StyleBuilder ( )
5959 . AddStyle ( "height: auto" )
6060 . AddStyle ( "min-height: 1.1876em" )
61- . AddStyle ( "display" , "inline" , Value != null || SelectedValues . Count ( ) != 0 )
61+ . AddStyle ( "display" , "inline" , Value != null || SelectedValues . Any ( ) )
6262 . Build ( ) ;
6363
6464 private string _elementId = "combobox_" + Guid . NewGuid ( ) . ToString ( ) . Substring ( 0 , 8 ) ;
@@ -581,7 +581,7 @@ protected Task UpdateDataVisualiserTextAsync()
581581 {
582582 if ( MultiSelectionTextFunc != null )
583583 {
584- if ( SelectedValues . Count ( ) == 0 )
584+ if ( ! SelectedValues . Any ( ) )
585585 {
586586 _dataVisualiserText = null ;
587587 return Task . CompletedTask ;
@@ -685,7 +685,8 @@ protected override async Task OnParametersSetAsync()
685685 else
686686 {
687687 DeselectAllItems ( ) ;
688- Items . FirstOrDefault ( x => x . Value . Equals ( Value ) ) . Selected = true ;
688+ if ( Value is not null )
689+ Items . FirstOrDefault ( x => x . Value . Equals ( Value ) ) . Selected = true ;
689690 }
690691 }
691692 if ( ( Value == null && _oldValue != null ) || ( Value != null && Value . Equals ( _oldValue ) == false ) )
@@ -1191,7 +1192,7 @@ protected void UpdateIcon()
11911192 protected override bool HasValue ( T value )
11921193 {
11931194 if ( MultiSelection )
1194- return SelectedValues ? . Count ( ) > 0 ;
1195+ return SelectedValues . Any ( ) ;
11951196 else
11961197 return base . HasValue ( value ) ;
11971198 }
@@ -1236,16 +1237,16 @@ protected async Task SelectAllItems()
12361237
12371238 protected bool ? GetAllSelectedState ( )
12381239 {
1239- if ( MultiSelection == true && SelectedValues . Count ( ) == Items . Count )
1240+ if ( MultiSelection )
12401241 {
1241- return true ;
1242- }
1242+ var count = SelectedValues . Count ( ) ;
1243+ if ( count == 0 )
1244+ return false ;
12431245
1244- if ( MultiSelection == true && SelectedValues . Count ( ) == 0 )
1245- {
1246- return false ;
1247- }
1246+ if ( count == Items . Count )
1247+ return true ;
12481248
1249+ }
12491250 return null ;
12501251 }
12511252
@@ -1279,16 +1280,20 @@ protected int GetActiveItemIndex()
12791280 protected int GetActiveProperItemIndex ( )
12801281 {
12811282 var properItems = GetEligibleAndNonDisabledItems ( ) ;
1282- if ( _lastActivatedItem == null )
1283- {
1284- var a = properItems . FindIndex ( x => x . Active == true ) ;
1285- return a ;
1286- }
1287- else
1283+ if ( properItems . Any ( ) )
12881284 {
1289- var a = properItems . FindIndex ( x => _lastActivatedItem . Value == null ? x . Value == null : Comparer != null ? Comparer . Equals ( _lastActivatedItem . Value , x . Value ) : _lastActivatedItem . Value . Equals ( x . Value ) ) ;
1290- return a ;
1285+ if ( _lastActivatedItem == null )
1286+ {
1287+ var a = properItems . FindIndex ( x => x . Active == true ) ;
1288+ return a ;
1289+ }
1290+ else
1291+ {
1292+ var a = properItems . FindIndex ( x => _lastActivatedItem . Value == null ? x . Value == null : Comparer != null ? Comparer . Equals ( _lastActivatedItem . Value , x . Value ) : _lastActivatedItem . Value . Equals ( x . Value ) ) ;
1293+ return a ;
1294+ }
12911295 }
1296+ return - 1 ;
12921297 }
12931298
12941299 protected T GetActiveItemValue ( )
@@ -1339,7 +1344,7 @@ public async Task ActiveFirstItem(string startChar = null)
13391344 }
13401345
13411346 // find first item that starts with the letter
1342- var possibleItems = Items . Where ( x => ( x . Text ?? Converter . Set ( x . Value ) ?? "" ) . StartsWith ( startChar , StringComparison . CurrentCultureIgnoreCase ) ) . ToList ( ) ;
1347+ var possibleItems = Items . Where ( x => ( x . Text ?? Converter . Set ( x . Value ) ?? "" ) . StartsWith ( startChar , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
13431348 if ( possibleItems == null || ! possibleItems . Any ( ) )
13441349 {
13451350 if ( _lastActivatedItem == null )
@@ -1404,8 +1409,13 @@ public async Task ActiveLastItem()
14041409 }
14051410 DeactiveAllItems ( ) ;
14061411 var properItems = GetEligibleAndNonDisabledItems ( ) ;
1407- properItems . Last ( ) . SetActive ( true ) ;
1408- _lastActivatedItem = properItems . Last ( ) ;
1412+ if ( properItems . Any ( ) )
1413+ {
1414+ properItems . Last ( ) . SetActive ( true ) ;
1415+ _lastActivatedItem = properItems . Last ( ) ;
1416+ }
1417+ else
1418+ _lastActivatedItem = null ;
14091419
14101420 await ScrollToMiddleAsync ( _lastActivatedItem ) ;
14111421 }
0 commit comments