Skip to content

Commit 3d2862e

Browse files
devversionandrewseguin
authored andcommitted
chore: add comment about mdc-form-field label and input linking
MDC recently made a change to the MDC text-field boilerplate. They now recommend using a `label` as container for the text-field. This has implications (code-wise and performance-wise) for us specifically since we support custom form-field controls and projected content. This commit adds a comment explaining on why we don't switch to a label as container element.
1 parent 60d6bd6 commit 3d2862e

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
<ng-template #labelTemplate>
2-
<!-- We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
3-
read if it comes before the control in the DOM. -->
2+
<!--
3+
MDC recommends that the text-field is a `<label>` element. This rather complicates the
4+
setup because it would require every form-field control to explicitly set `aria-labelledby`.
5+
This is because the `<label>` itself contains more than the actual label (e.g. prefix, suffix
6+
or other projected content), and screen readers could potentially read out undesired content.
7+
Excluding elements from being printed out requires them to be marked with `aria-hidden`, or
8+
the form control is set to a scoped element for the label (using `aria-labelledby`). Both of
9+
these options seem to complicate the setup because we know exactly what content is rendered
10+
as part of the label, and we don't want to spend resources on walking through projected content
11+
to set `aria-hidden`. Nor do we want to set `aria-labelledby` on every form control if we could
12+
simply link the label to the control using the label `for` attribute.
13+
14+
*Note*: We add aria-owns as a workaround for an issue in JAWS & NVDA where the label isn't
15+
read if it comes before the control in the DOM.
16+
-->
417
<label matFormFieldFloatingLabel [floating]="_shouldLabelFloat()"
518
*ngIf="_hasFloatingLabel()"
619
(cdkObserveContent)="_refreshOutlineNotchWidth()"

0 commit comments

Comments
 (0)