@@ -437,6 +437,7 @@ export class MatFormField
437
437
this . _stateChanges = control . stateChanges . subscribe ( ( ) => {
438
438
this . _updateFocusState ( ) ;
439
439
this . _syncDescribedByIds ( ) ;
440
+ this . _showOrHideSubscript ( ) ;
440
441
this . _changeDetectorRef . markForCheck ( ) ;
441
442
} ) ;
442
443
@@ -478,17 +479,20 @@ export class MatFormField
478
479
// Re-validate when the number of hints changes.
479
480
this . _hintChildren . changes . subscribe ( ( ) => {
480
481
this . _processHints ( ) ;
482
+ this . _showOrHideSubscript ( ) ;
481
483
this . _changeDetectorRef . markForCheck ( ) ;
482
484
} ) ;
483
485
484
486
// Update the aria-described by when the number of errors changes.
485
487
this . _errorChildren . changes . subscribe ( ( ) => {
486
488
this . _syncDescribedByIds ( ) ;
489
+ this . _showOrHideSubscript ( ) ;
487
490
this . _changeDetectorRef . markForCheck ( ) ;
488
491
} ) ;
489
492
490
493
// Initial mat-hint validation and subscript describedByIds sync.
491
494
this . _validateHints ( ) ;
495
+ this . _showOrHideSubscript ( ) ;
492
496
this . _syncDescribedByIds ( ) ;
493
497
}
494
498
@@ -682,6 +686,45 @@ export class MatFormField
682
686
}
683
687
}
684
688
689
+ /**
690
+ * Solves https://github.com/angular/components/issues/29616
691
+ * Issues with certain browser and screen reader pairings not able to announce mat-error
692
+ * when it's added to the DOM rather than changing the visibility of the hint/error wrappers.
693
+ * Changing visibility instead of adding the div wrappers works for all browsers and sreen
694
+ * readers.
695
+ *
696
+ * If there is an 'error' or 'hint' message being returned, remove visibility: hidden
697
+ * style class and show error or hint section of code. If no 'error' or 'hint' messages are
698
+ * being returned and no error children showing in query list, add visibility: hidden
699
+ * style class back to error wrapper.
700
+ */
701
+ private _showOrHideSubscript ( ) {
702
+ switch ( this . _getDisplayedMessages ( ) ) {
703
+ case 'error' : {
704
+ console . log ( this . _elementRef . nativeElement . children [ 1 ] . children [ 0 ] . classList ) ;
705
+ this . _elementRef . nativeElement . children [ 1 ] . children [ 0 ] . classList . remove (
706
+ 'mat-mdc-form-field-error-wrapper--hidden' ,
707
+ ) ;
708
+ console . log ( this . _elementRef . nativeElement . children [ 1 ] . children [ 0 ] . classList ) ;
709
+ break ;
710
+ }
711
+ case 'hint' : {
712
+ console . log ( this . _elementRef . nativeElement . children [ 1 ] . children [ 1 ] . classList ) ;
713
+ this . _elementRef . nativeElement . children [ 1 ] . children [ 1 ] . classList . remove (
714
+ 'mat-mdc-form-field-hint-wrapper--hidden' ,
715
+ ) ;
716
+ console . log ( this . _elementRef . nativeElement . children [ 1 ] . children [ 1 ] . classList ) ;
717
+ break ;
718
+ }
719
+ }
720
+
721
+ if ( ! this . _errorChildren || this . _errorChildren . length === 0 || ! this . _control . errorState ) {
722
+ this . _elementRef . nativeElement . children [ 1 ] . children [ 0 ] . classList . add (
723
+ 'mat-mdc-form-field-error-wrapper--hidden' ,
724
+ ) ;
725
+ }
726
+ }
727
+
685
728
/**
686
729
* Updates the horizontal offset of the label in the outline appearance. In the outline
687
730
* appearance, the notched-outline and label are not relative to the infix container because
0 commit comments