Skip to content

Commit 977f46f

Browse files
authored
fix(material/form-field): restore error message animation (#31774)
When a form becomes invalid and displays an error, the error message was no longer animating. This regression was introduced in #30678 (accessibility changes), because error elements were no longer destroyed/re-rendered, preventing the CSS animation from running. This fix ensures that the animation works again without impacting accessibility. Fixes #31712
1 parent f004728 commit 977f46f

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

src/material/form-field/form-field.html

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,28 @@
9595
}
9696
</div>
9797

98-
<div
99-
class="mat-mdc-form-field-subscript-wrapper mat-mdc-form-field-bottom-align"
100-
[class.mat-mdc-form-field-subscript-dynamic-size]="subscriptSizing === 'dynamic'"
98+
<div aria-atomic="true" aria-live="polite"
99+
class="mat-mdc-form-field-subscript-wrapper mat-mdc-form-field-bottom-align"
100+
[class.mat-mdc-form-field-subscript-dynamic-size]="subscriptSizing === 'dynamic'"
101101
>
102102
@let subscriptMessageType = _getSubscriptMessageType();
103103

104-
<!--
105-
Use a single permanent wrapper for both hints and errors so aria-live works correctly,
106-
as having it appear post render will not consistently work. We also do not want to add
107-
additional divs as it causes styling regressions.
108-
-->
109-
<div aria-atomic="true" aria-live="polite"
110-
[class.mat-mdc-form-field-error-wrapper]="subscriptMessageType === 'error'"
111-
[class.mat-mdc-form-field-hint-wrapper]="subscriptMessageType === 'hint'"
112-
>
113-
@switch (subscriptMessageType) {
114-
@case ('error') {
104+
@switch (subscriptMessageType) {
105+
@case ('error') {
106+
<div class="mat-mdc-form-field-error-wrapper">
115107
<ng-content select="mat-error, [matError]"></ng-content>
116-
}
108+
</div>
109+
}
117110

118-
@case ('hint') {
111+
@case ('hint') {
112+
<div class="mat-mdc-form-field-hint-wrapper">
119113
@if (hintLabel) {
120114
<mat-hint [id]="_hintLabelId">{{hintLabel}}</mat-hint>
121115
}
122116
<ng-content select="mat-hint:not([align='end'])"></ng-content>
123117
<div class="mat-mdc-form-field-hint-spacer"></div>
124118
<ng-content select="mat-hint[align='end']"></ng-content>
125-
}
119+
</div>
126120
}
127-
</div>
121+
}
128122
</div>

0 commit comments

Comments
 (0)