@@ -18,26 +18,13 @@ public partial class Select<TValue> : ISelect, ILookup
1818 [ NotNull ]
1919 private SwalService ? SwalService { get ; set ; }
2020
21- private string ? ClassString => CssBuilder . Default ( "select dropdown" )
22- . AddClass ( "is-clearable" , IsClearable )
23- . AddClassFromAttributes ( AdditionalAttributes )
24- . Build ( ) ;
25-
26- private string ? InputClassString => CssBuilder . Default ( "form-select form-control" )
27- . AddClass ( $ "border-{ Color . ToDescriptionString ( ) } ", Color != Color . None && ! IsDisabled && ! IsValid . HasValue )
28- . AddClass ( $ "border-success", IsValid . HasValue && IsValid . Value )
29- . AddClass ( $ "border-danger", IsValid . HasValue && ! IsValid . Value )
30- . AddClass ( CssClass ) . AddClass ( ValidCss )
31- . Build ( ) ;
32-
33- private string ? ActiveItem ( SelectedItem item ) => CssBuilder . Default ( "dropdown-item" )
34- . AddClass ( "active" , item . Value == CurrentValueAsString )
35- . AddClass ( "disabled" , item . IsDisabled )
36- . Build ( ) ;
37-
38- private readonly List < SelectedItem > _children = [ ] ;
21+ [ Inject ]
22+ [ NotNull ]
23+ private IStringLocalizer < Select < TValue > > ? Localizer { get ; set ; }
3924
40- private string ? ScrollIntoViewBehaviorString => ScrollIntoViewBehavior == ScrollIntoViewBehavior . Smooth ? null : ScrollIntoViewBehavior . ToDescriptionString ( ) ;
25+ [ Inject ]
26+ [ NotNull ]
27+ private ILookupService ? InjectLookupService { get ; set ; }
4128
4229 /// <summary>
4330 /// Gets or sets the display template. Default is null.
@@ -124,31 +111,35 @@ public partial class Select<TValue> : ISelect, ILookup
124111 [ Parameter ]
125112 public string ? DefaultVirtualizeItemText { get ; set ; }
126113
127- /// <summary>
128- /// <inheritdoc/>
129- /// </summary>
130- IEnumerable < SelectedItem > ? ILookup . Lookup { get ; set ; }
114+ IEnumerable < SelectedItem > ? ILookup . Lookup { get => Items ; set => Items = value ; }
115+
116+ StringComparison ILookup . LookupStringComparison { get => StringComparison ; set => StringComparison = value ; }
131117
132118 /// <summary>
133119 /// <inheritdoc/>
134120 /// </summary>
135- StringComparison ILookup . LookupStringComparison { get ; set ; }
121+ protected override string ? RetrieveId ( ) => InputId ;
136122
137- [ Inject ]
138- [ NotNull ]
139- private IStringLocalizer < Select < TValue > > ? Localizer { get ; set ; }
123+ private string ? ClassString => CssBuilder . Default ( "select dropdown" )
124+ . AddClass ( "is-clearable" , IsClearable )
125+ . AddClassFromAttributes ( AdditionalAttributes )
126+ . Build ( ) ;
140127
141- /// <summary>
142- /// Gets or sets the injected lookup service instance.
143- /// </summary>
144- [ Inject ]
145- [ NotNull ]
146- private ILookupService ? InjectLookupService { get ; set ; }
128+ private string ? InputClassString => CssBuilder . Default ( "form-select form-control" )
129+ . AddClass ( $ "border- { Color . ToDescriptionString ( ) } " , Color != Color . None && ! IsDisabled && ! IsValid . HasValue )
130+ . AddClass ( $ "border-success" , IsValid . HasValue && IsValid . Value )
131+ . AddClass ( $ "border-danger" , IsValid . HasValue && ! IsValid . Value )
132+ . AddClass ( CssClass ) . AddClass ( ValidCss )
133+ . Build ( ) ;
147134
148- /// <summary>
149- /// <inheritdoc/>
150- /// </summary>
151- protected override string ? RetrieveId ( ) => InputId ;
135+ private string ? ActiveItem ( SelectedItem item ) => CssBuilder . Default ( "dropdown-item" )
136+ . AddClass ( "active" , item . Value == CurrentValueAsString )
137+ . AddClass ( "disabled" , item . IsDisabled )
138+ . Build ( ) ;
139+
140+ private readonly List < SelectedItem > _children = [ ] ;
141+
142+ private string ? ScrollIntoViewBehaviorString => ScrollIntoViewBehavior == ScrollIntoViewBehavior . Smooth ? null : ScrollIntoViewBehavior . ToDescriptionString ( ) ;
152143
153144 private string ? InputId => $ "{ Id } _input";
154145
@@ -169,44 +160,6 @@ private SelectedItem? SelectedRow
169160 }
170161 }
171162
172- private SelectedItem ? GetSelectedRow ( )
173- {
174- if ( Value is null )
175- {
176- _lastSelectedValueString = "" ;
177- _init = false ;
178- return null ;
179- }
180-
181- var item = IsVirtualize ? GetItemByVirtualized ( ) : GetItemByRows ( ) ;
182- if ( item != null )
183- {
184- if ( _init && DisableItemChangedWhenFirstRender )
185- {
186-
187- }
188- else
189- {
190- _ = SelectedItemChanged ( item ) ;
191- _init = false ;
192- }
193- }
194- return item ;
195- }
196-
197- private SelectedItem ? GetItemWithEnumValue ( ) => ValueType . IsEnum ? Rows . Find ( i => i . Value == Convert . ToInt32 ( Value ) . ToString ( ) ) : null ;
198-
199- private SelectedItem GetItemByVirtualized ( ) => new ( CurrentValueAsString , _defaultVirtualizedItemText ) ;
200-
201- private SelectedItem ? GetItemByRows ( )
202- {
203- var item = GetItemWithEnumValue ( )
204- ?? Rows . Find ( i => i . Value == CurrentValueAsString )
205- ?? Rows . Find ( i => i . Active )
206- ?? Rows . FirstOrDefault ( i => ! i . IsDisabled ) ;
207- return item ;
208- }
209-
210163 /// <summary>
211164 /// <inheritdoc/>
212165 /// </summary>
@@ -440,4 +393,42 @@ private async Task OnChange(ChangeEventArgs args)
440393 }
441394 }
442395 }
396+
397+ private SelectedItem ? GetSelectedRow ( )
398+ {
399+ if ( Value is null )
400+ {
401+ _lastSelectedValueString = "" ;
402+ _init = false ;
403+ return null ;
404+ }
405+
406+ var item = IsVirtualize ? GetItemByVirtualized ( ) : GetItemByRows ( ) ;
407+ if ( item != null )
408+ {
409+ if ( _init && DisableItemChangedWhenFirstRender )
410+ {
411+
412+ }
413+ else
414+ {
415+ _ = SelectedItemChanged ( item ) ;
416+ _init = false ;
417+ }
418+ }
419+ return item ;
420+ }
421+
422+ private SelectedItem ? GetItemWithEnumValue ( ) => ValueType . IsEnum ? Rows . Find ( i => i . Value == Convert . ToInt32 ( Value ) . ToString ( ) ) : null ;
423+
424+ private SelectedItem GetItemByVirtualized ( ) => new ( CurrentValueAsString , _defaultVirtualizedItemText ) ;
425+
426+ private SelectedItem ? GetItemByRows ( )
427+ {
428+ var item = GetItemWithEnumValue ( )
429+ ?? Rows . Find ( i => i . Value == CurrentValueAsString )
430+ ?? Rows . Find ( i => i . Active )
431+ ?? Rows . FirstOrDefault ( i => ! i . IsDisabled ) ;
432+ return item ;
433+ }
443434}
0 commit comments