11using Microsoft . AspNetCore . Components ;
22using Microsoft . AspNetCore . Components . Web ;
33using MudBlazor ;
4+ using MudBlazor . Interfaces ;
45using MudBlazor . State ;
56using MudBlazor . Utilities ;
67
@@ -53,7 +54,8 @@ private async Task OnCountChanged()
5354 /// </summary>
5455 protected string ? Classname =>
5556 new CssBuilder ( $ "d-flex gap-{ Spacing } ")
56- . AddClass ( Class )
57+ . AddClass ( "mud-code-input-inner" )
58+ . AddClass ( InnerClass )
5759 . Build ( ) ;
5860
5961 /// <summary>
@@ -74,6 +76,20 @@ private async Task OnCountChanged()
7476 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
7577 public string ? InputClass { get ; set ; }
7678
79+ /// <summary>
80+ /// The CSS classes for input container div, seperated by space.
81+ /// </summary>
82+ [ Parameter ]
83+ [ Category ( CategoryTypes . FormComponent . Behavior ) ]
84+ public string ? InnerClass { get ; set ; }
85+
86+ /// <summary>
87+ /// The CSS styles for input container div.
88+ /// </summary>
89+ [ Parameter ]
90+ [ Category ( CategoryTypes . FormComponent . Behavior ) ]
91+ public string ? InnerStyle { get ; set ; }
92+
7793 /// <summary>
7894 /// Type of the input element. It should be a valid HTML5 input type.
7995 /// </summary>
@@ -137,8 +153,15 @@ private async Task OnCountChanged()
137153 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
138154 public Margin Margin { get ; set ; }
139155
156+ bool _skipInputEvent = false ;
157+ bool _skipRefocus = false ;
140158 private async Task OnInputHandler ( )
141159 {
160+ if ( _skipInputEvent )
161+ {
162+ _skipInputEvent = false ;
163+ return ;
164+ }
142165 await FocusNext ( ) ;
143166 }
144167
@@ -154,32 +177,49 @@ protected async Task HandleKeyDown(KeyboardEventArgs arg)
154177 return ;
155178 }
156179
157- if ( RuntimeLocation . IsClientSide )
158- {
159- await Task . Delay ( 10 ) ;
160- }
161-
162- if ( arg . Key == "Backspace" || arg . Key == "ArrowLeft" )
180+ if ( arg . Key == "Backspace" || arg . Key == "ArrowLeft" || arg . Key == "Delete" )
163181 {
182+ _skipInputEvent = true ;
183+ _skipRefocus = true ;
184+ if ( arg . Key == "Delete" )
185+ {
186+ await _elementReferences [ _lastFocusedIndex ] . Clear ( ) ;
187+ _skipInputEvent = false ;
188+ }
189+ if ( RuntimeLocation . IsClientSide )
190+ {
191+ await Task . Delay ( 10 ) ;
192+ }
164193 await FocusPrevious ( ) ;
165194 return ;
166195 }
167196
168197 if ( arg . Key == "ArrowRight" )
169198 {
199+ if ( RuntimeLocation . IsClientSide )
200+ {
201+ await Task . Delay ( 10 ) ;
202+ }
170203 await FocusNext ( ) ;
171204 }
172-
205+
173206 }
174207
175208 private int _lastFocusedIndex = 0 ;
176209 /// <summary>
177210 ///
178211 /// </summary>
179212 /// <param name="count"></param>
180- protected void CheckFocus ( int count )
213+ protected async Task CheckFocus ( int count )
181214 {
182215 _lastFocusedIndex = count ;
216+ if ( _skipRefocus == true )
217+ {
218+ _skipRefocus = false ;
219+ return ;
220+ }
221+ string str = Converter . Set ( _theValue . Value ) ?? string . Empty ;
222+ await _elementReferences [ str . Length ] . FocusAsync ( ) ;
183223 }
184224
185225 /// <summary>
@@ -236,7 +276,7 @@ private void SyncReferences()
236276 /// <returns></returns>
237277 public async Task SetValue ( )
238278 {
239- string result = "" ;
279+ string result = "" ;
240280 for ( int i = 0 ; i < _count . Value ; i ++ )
241281 {
242282 var val = _elementReferences [ i ] . Value ? . ToString ( ) ;
0 commit comments