1010
1111namespace MudExtensions
1212{
13- public partial class MudComboBox < T > : MudBaseInputExtended < T >
13+ public partial class MudComboBox < T > : MudBaseInputExtended < T > , IDisposable
1414 {
1515 #region Constructor, Injected Services, Parameters, Fields
1616
@@ -31,7 +31,7 @@ protected internal void SetSearchString(T value)
3131 }
3232
3333 internal string _searchString { get ; set ; }
34- private string multiSelectionText ;
34+ private readonly string multiSelectionText ;
3535 private IKeyInterceptor _keyInterceptor ;
3636
3737 public List < MudComboBoxItem < T > > Items { get ; set ; } = new ( ) ;
@@ -65,8 +65,8 @@ protected internal void SetSearchString(T value)
6565 . AddStyle ( "display" , "inline" , Value != null || SelectedValues . Any ( ) )
6666 . Build ( ) ;
6767
68- private string _elementId = string . Concat ( "combobox_" , Guid . NewGuid ( ) . ToString ( ) . AsSpan ( 0 , 8 ) ) ;
69- private string _popoverId = string . Concat ( "comboboxpopover_" , Guid . NewGuid ( ) . ToString ( ) . AsSpan ( 0 , 8 ) ) ;
68+ private readonly string _elementId = string . Concat ( "combobox_" , Guid . NewGuid ( ) . ToString ( ) . AsSpan ( 0 , 8 ) ) ;
69+ private readonly string _popoverId = string . Concat ( "comboboxpopover_" , Guid . NewGuid ( ) . ToString ( ) . AsSpan ( 0 , 8 ) ) ;
7070
7171 /// <summary>
7272 /// If true, combobox goes to autocomplete mode.
@@ -535,7 +535,7 @@ public IEnumerable<T> SelectedValues
535535
536536 protected Task UpdateDataVisualiserTextAsync ( )
537537 {
538- List < string > textList = new List < string > ( ) ;
538+ var textList = new List < string > ( ) ;
539539 if ( Items != null && Items . Any ( ) )
540540 {
541541 if ( false ) // ItemCollection != null
@@ -1032,7 +1032,7 @@ protected internal async Task ToggleOption(MudComboBoxItem<T> item, bool selecte
10321032 {
10331033 if ( ToggleSelection )
10341034 {
1035- await UpdateComboBoxValueAsync ( default ( T ) , updateText : true , updateSearchString : true ) ;
1035+ await UpdateComboBoxValueAsync ( default , updateText : true , updateSearchString : true ) ;
10361036 item . Selected = false ;
10371037 }
10381038 }
@@ -1115,14 +1115,7 @@ public async Task BeginValidatePublic()
11151115 return result ;
11161116 }
11171117
1118- protected internal void Remove ( MudComboBoxItem < T > item )
1119- {
1120- if ( Items == null )
1121- {
1122- return ;
1123- }
1124- Items . Remove ( item ) ;
1125- }
1118+ protected internal void RemoveItem ( MudComboBoxItem < T > item ) => Items . Remove ( item ) ;
11261119
11271120 #endregion
11281121
@@ -1134,7 +1127,7 @@ protected internal void Remove(MudComboBoxItem<T> item)
11341127 /// </summary>
11351128 protected async ValueTask ClearButtonClickHandlerAsync ( MouseEventArgs e )
11361129 {
1137- await UpdateComboBoxValueAsync ( default ( T ) ) ;
1130+ await UpdateComboBoxValueAsync ( default ) ;
11381131 _searchString = null ;
11391132 await SetTextAsync ( default , false ) ;
11401133 _selectedValues . Clear ( ) ;
@@ -1313,7 +1306,6 @@ protected void DeactiveAllItems()
13131306 }
13141307 }
13151308
1316- #pragma warning disable BL0005
13171309 public async Task ActiveFirstItem ( string startChar = null )
13181310 {
13191311 if ( Items == null || Items . Count == 0 || Items [ 0 ] . Disabled )
@@ -1407,7 +1399,6 @@ public async Task ActiveLastItem()
14071399 if ( _lastActivatedItem is not null )
14081400 await ScrollToMiddleAsync ( _lastActivatedItem ) ;
14091401 }
1410- #pragma warning restore BL0005
14111402
14121403 #endregion
14131404
@@ -1439,5 +1430,11 @@ protected Typo GetTypo()
14391430
14401431 protected internal ValueTask ScrollToMiddleAsync ( MudComboBoxItem < T > item ) =>
14411432 item is not null ? ScrollManagerExtended . ScrollToMiddleAsync ( _popoverId , item . ItemId ) : ValueTask . CompletedTask ;
1433+
1434+
1435+ public void Dispose ( )
1436+ {
1437+ Items . Clear ( ) ;
1438+ }
14421439 }
14431440}
0 commit comments