@@ -292,8 +292,21 @@ export class BaseTextInput extends FASTElement {
292292 *
293293 * @internal
294294 */
295+ @observable
295296 public control ! : HTMLInputElement ;
296297
298+ /**
299+ * Calls the `setValidity` method when the control reference changes.
300+ *
301+ * @param prev - the previous control reference
302+ * @param next - the current control reference
303+ *
304+ * @internal
305+ */
306+ public controlChanged ( prev : HTMLInputElement | undefined , next : HTMLInputElement | undefined ) : void {
307+ this . setValidity ( ) ;
308+ }
309+
297310 /**
298311 * A reference to the internal label element.
299312 *
@@ -589,18 +602,18 @@ export class BaseTextInput extends FASTElement {
589602 *
590603 * @internal
591604 */
592- public setValidity (
593- flags : Partial < ValidityState > = this . control . validity ,
594- message : string = this . validationMessage ,
595- anchor : HTMLElement = this . control ,
596- ) : void {
597- if ( this . $fastController . isConnected ) {
605+ public setValidity ( flags ?: Partial < ValidityState > , message ?: string , anchor ?: HTMLElement ) : void {
606+ if ( this . $fastController . isConnected && this . control ) {
598607 if ( this . disabled ) {
599608 this . elementInternals . setValidity ( { } ) ;
600609 return ;
601610 }
602611
603- this . elementInternals . setValidity ( flags , message , anchor ) ;
612+ this . elementInternals . setValidity (
613+ flags ?? this . control . validity ,
614+ message ?? this . validationMessage ,
615+ anchor ?? this . control ,
616+ ) ;
604617 }
605618 }
606619}
0 commit comments