@@ -13,7 +13,11 @@ namespace MudExtensions
1313 public abstract class MudBaseInputExtended < T > : MudFormComponent < T , string >
1414 {
1515 private bool _isDirty ;
16+ private bool _validated ;
1617
18+ /// <summary>
19+ ///
20+ /// </summary>
1721 protected MudBaseInputExtended ( ) : base ( new DefaultConverter < T > ( ) ) { }
1822
1923 [ CascadingParameter ( Name = "ParentDisabled" ) ] private bool ParentDisabled { get ; set ; }
@@ -72,7 +76,7 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
7276 /// </summary>
7377 [ Parameter ]
7478 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
75- public string HelperText { get ; set ; }
79+ public string ? HelperText { get ; set ; }
7680
7781 /// <summary>
7882 /// If true, the helper text will only be visible on focus.
@@ -86,14 +90,14 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
8690 /// </summary>
8791 [ Parameter ]
8892 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
89- public string AdornmentIcon { get ; set ; }
93+ public string ? AdornmentIcon { get ; set ; }
9094
9195 /// <summary>
9296 /// Text that will be used if Adornment is set to Start or End, the Text overrides Icon.
9397 /// </summary>
9498 [ Parameter ]
9599 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
96- public string AdornmentText { get ; set ; }
100+ public string ? AdornmentText { get ; set ; }
97101
98102 /// <summary>
99103 /// The Adornment if used. By default, it is set to None.
@@ -107,14 +111,21 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
107111 /// </summary>
108112 [ Parameter ]
109113 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
110- public RenderFragment AdornmentStart { get ; set ; }
114+ public RenderFragment ? AdornmentStart { get ; set ; }
111115
112116 /// <summary>
113117 /// The Adornment if used. By default, it is set to None.
114118 /// </summary>
115119 [ Parameter ]
116120 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
117- public RenderFragment AdornmentEnd { get ; set ; }
121+ public RenderFragment ? AdornmentEnd { get ; set ; }
122+
123+ /// <summary>
124+ /// The aria-label of the adornment.
125+ /// </summary>
126+ [ Parameter ]
127+ [ Category ( CategoryTypes . FormComponent . Appearance ) ]
128+ public string ? AdornmentAriaLabel { get ; set ; } = string . Empty ;
118129
119130 /// <summary>
120131 /// The validation is only triggered if the user has changed the input value at least once. By default, it is false
@@ -128,7 +139,7 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
128139 /// </summary>
129140 [ Parameter ]
130141 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
131- public bool ForceShrink { get ; set ; }
142+ public bool ShrinkLabel { get ; set ; }
132143
133144 /// <summary>
134145 /// The color of the adornment if used. It supports the theme colors.
@@ -137,13 +148,6 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
137148 [ Category ( CategoryTypes . FormComponent . Appearance ) ]
138149 public Color AdornmentColor { get ; set ; } = Color . Default ;
139150
140- /// <summary>
141- /// The aria-label of the adornment.
142- /// </summary>
143- [ Parameter ]
144- [ Category ( CategoryTypes . FormComponent . Appearance ) ]
145- public string AdornmentAriaLabel { get ; set ; } = string . Empty ;
146-
147151 /// <summary>
148152 /// The Icon Size.
149153 /// </summary>
@@ -175,7 +179,7 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
175179 /// </summary>
176180 [ Parameter ]
177181 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
178- public string Placeholder { get ; set ; }
182+ public string ? Placeholder { get ; set ; }
179183
180184 /// <summary>
181185 /// If set, will display the counter, value 0 will display current count but no stop count.
@@ -196,7 +200,7 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
196200 /// </summary>
197201 [ Parameter ]
198202 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
199- public string Label { get ; set ; }
203+ public string ? Label { get ; set ; }
200204
201205 /// <summary>
202206 /// If true the input will focus automatically.
@@ -242,13 +246,13 @@ protected MudBaseInputExtended() : base(new DefaultConverter<T>()) { }
242246 /// </summary>
243247 [ Parameter ]
244248 [ Category ( CategoryTypes . FormComponent . Validation ) ]
245- public virtual string Pattern { get ; set ; }
249+ public virtual string ? Pattern { get ; set ; }
246250
247251 /// <summary>
248252 /// CSS style of the child content.
249253 /// </summary>
250254 [ Parameter ]
251- public string ChildContentStyle { get ; set ; }
255+ public string ? ChildContentStyle { get ; set ; }
252256
253257 /// <summary>
254258 /// Sync the value, values and text, calls validation manually. Useful to call after user changes value or text programmatically.
@@ -264,11 +268,18 @@ public virtual async Task ForceUpdate()
264268 /// </summary>
265269 internal virtual InputType GetInputType ( ) { return InputType . Text ; }
266270
271+ /// <summary>
272+ ///
273+ /// </summary>
274+ /// <param name="text"></param>
275+ /// <param name="updateValue"></param>
276+ /// <returns></returns>
267277 protected virtual async Task SetTextAsync ( string ? text , bool updateValue = true )
268278 {
269279 if ( Text != text )
270280 {
271281 Text = text ;
282+ _validated = false ;
272283 if ( ! string . IsNullOrWhiteSpace ( Text ) )
273284 Touched = true ;
274285 if ( updateValue )
@@ -314,7 +325,7 @@ protected virtual Task UpdateTextPropertyAsync(bool updateValue)
314325 /// <summary>
315326 /// Fired when the text value changes.
316327 /// </summary>
317- [ Parameter ] public EventCallback < string > TextChanged { get ; set ; }
328+ [ Parameter ] public EventCallback < string ? > TextChanged { get ; set ; }
318329
319330 /// <summary>
320331 /// Fired when the element loses focus.
@@ -327,16 +338,32 @@ protected virtual Task UpdateTextPropertyAsync(bool updateValue)
327338 [ Parameter ]
328339 public EventCallback < ChangeEventArgs > OnInternalInputChanged { get ; set ; }
329340
341+ /// <summary>
342+ ///
343+ /// </summary>
330344 protected bool _isFocused ;
331345
346+ /// <summary>
347+ ///
348+ /// </summary>
349+ /// <param name="obj"></param>
350+ /// <returns></returns>
332351 protected internal virtual async Task OnBlurredAsync ( FocusEventArgs obj )
333352 {
353+ if ( ReadOnly )
354+ {
355+ return ;
356+ }
357+
334358 _isFocused = false ;
335359
336360 if ( ! OnlyValidateIfDirty || _isDirty )
337361 {
338362 Touched = true ;
339- await BeginValidationAfterAsync ( OnBlur . InvokeAsync ( obj ) ) ;
363+ if ( _validated )
364+ await OnBlur . InvokeAsync ( obj ) ;
365+ else
366+ await BeginValidationAfterAsync ( OnBlur . InvokeAsync ( obj ) ) ;
340367 }
341368 }
342369
@@ -345,7 +372,12 @@ protected internal virtual async Task OnBlurredAsync(FocusEventArgs obj)
345372 /// </summary>
346373 [ Parameter ] public EventCallback < KeyboardEventArgs > OnKeyDown { get ; set ; }
347374
348- protected virtual async Task InvokeKeyDown ( KeyboardEventArgs obj )
375+ /// <summary>
376+ ///
377+ /// </summary>
378+ /// <param name="obj"></param>
379+ /// <returns></returns>
380+ protected virtual async Task InvokeKeyDownAsync ( KeyboardEventArgs obj )
349381 {
350382 _isFocused = true ;
351383 await OnKeyDown . InvokeAsync ( obj ) ;
@@ -365,30 +397,17 @@ protected virtual async Task InvokeKeyDown(KeyboardEventArgs obj)
365397 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
366398 public bool DisablePaste { get ; set ; }
367399
368-
369- /// <summary>
370- /// Fired on the KeyPress event.
371- /// </summary>
372- [ Parameter ] public EventCallback < KeyboardEventArgs > OnKeyPress { get ; set ; }
373-
374- protected virtual async Task InvokeKeyPress ( KeyboardEventArgs obj )
375- {
376- await OnKeyPress . InvokeAsync ( obj ) ;
377- }
378-
379- /// <summary>
380- /// Prevent the default action for the KeyPress event.
381- /// </summary>
382- [ Parameter ]
383- [ Category ( CategoryTypes . FormComponent . Behavior ) ]
384- public bool KeyPressPreventDefault { get ; set ; }
385-
386400 /// <summary>
387401 /// Fired on the KeyUp event.
388402 /// </summary>
389403 [ Parameter ] public EventCallback < KeyboardEventArgs > OnKeyUp { get ; set ; }
390404
391- protected virtual async Task InvokeKeyUp ( KeyboardEventArgs obj )
405+ /// <summary>
406+ ///
407+ /// </summary>
408+ /// <param name="obj"></param>
409+ /// <returns></returns>
410+ protected virtual async Task InvokeKeyUpAsync ( KeyboardEventArgs obj )
392411 {
393412 _isFocused = true ;
394413 await OnKeyUp . InvokeAsync ( obj ) ;
@@ -418,11 +437,19 @@ public T? Value
418437 set => _value = value ;
419438 }
420439
440+ /// <summary>
441+ ///
442+ /// </summary>
443+ /// <param name="value"></param>
444+ /// <param name="updateText"></param>
445+ /// <param name="force"></param>
446+ /// <returns></returns>
421447 protected virtual async Task SetValueAsync ( T ? value , bool updateText = true , bool force = false )
422448 {
423449 if ( ! EqualityComparer < T ? > . Default . Equals ( Value , value ) || force == true )
424450 {
425451 _isDirty = true ;
452+ _validated = false ;
426453 Value = value ;
427454 await ValueChanged . InvokeAsync ( Value ) ;
428455 if ( updateText )
@@ -440,6 +467,11 @@ protected virtual Task UpdateValuePropertyAsync(bool updateText)
440467 return SetValueAsync ( Converter . Get ( Text ) , updateText ) ;
441468 }
442469
470+ /// <summary>
471+ ///
472+ /// </summary>
473+ /// <param name="value"></param>
474+ /// <returns></returns>
443475 protected override bool SetConverter ( MudBlazor . Converter < T , string > value )
444476 {
445477 var changed = base . SetConverter ( value ) ;
@@ -449,6 +481,11 @@ protected override bool SetConverter(MudBlazor.Converter<T, string> value)
449481 return changed ;
450482 }
451483
484+ /// <summary>
485+ ///
486+ /// </summary>
487+ /// <param name="value"></param>
488+ /// <returns></returns>
452489 protected override bool SetCulture ( CultureInfo value )
453490 {
454491 var changed = base . SetCulture ( value ) ;
@@ -463,13 +500,18 @@ protected override bool SetCulture(CultureInfo value)
463500 /// </summary>
464501 [ Parameter ]
465502 [ Category ( CategoryTypes . FormComponent . Behavior ) ]
466- public string Format
503+ public string ? Format
467504 {
468505 get => ( ( Converter < T > ) Converter ) . Format ;
469506 set => SetFormat ( value ) ;
470507 }
471508
472- protected virtual bool SetFormat ( string value )
509+ /// <summary>
510+ ///
511+ /// </summary>
512+ /// <param name="value"></param>
513+ /// <returns></returns>
514+ protected virtual bool SetFormat ( string ? value )
473515 {
474516 var changed = Format != value ;
475517 if ( changed )
@@ -480,12 +522,17 @@ protected virtual bool SetFormat(string value)
480522 return changed ;
481523 }
482524
483- protected override Task ValidateValue ( )
525+ /// <summary>
526+ ///
527+ /// </summary>
528+ /// <returns></returns>
529+ protected override async Task ValidateValue ( )
484530 {
485531 if ( SubscribeToParentFormExtended )
486- return base . ValidateValue ( ) ;
487-
488- return Task . CompletedTask ;
532+ {
533+ _validated = true ;
534+ await base . ValidateValue ( ) ;
535+ }
489536 }
490537
491538 /// <summary>
@@ -516,9 +563,13 @@ public virtual async Task ForceRender(bool forceTextUpdate)
516563 await UpdateTextPropertyAsync ( false ) ;
517564 StateHasChanged ( ) ;
518565 }
519-
566+ /// <summary>
567+ ///
568+ /// </summary>
520569 protected bool _forceTextUpdate ;
521-
570+ /// <summary>
571+ ///
572+ /// </summary>
522573 protected virtual bool SkipUpdateProcessOnSetParameters { get ; set ; }
523574
524575 /// <summary>
@@ -582,11 +633,16 @@ protected override void OnParametersSet()
582633 base . OnParametersSet ( ) ;
583634 }
584635
585- protected override void ResetValue ( )
636+ /// <summary>
637+ ///
638+ /// </summary>
639+ /// <returns></returns>
640+ protected override async Task ResetValueAsync ( )
586641 {
587- SetTextAsync ( null , updateValue : true ) . AndForget ( ) ;
642+ await SetTextAsync ( null , updateValue : true ) ;
588643 _isDirty = false ;
589- base . ResetValueAsync ( ) ;
644+ _validated = false ;
645+ await base . ResetValueAsync ( ) ;
590646 }
591647
592648 [ CascadingParameter ( Name = "SubscribeToParentFormExtended" ) ]
0 commit comments