Skip to content

feat(material/form-field): add MatLabel input property to change use of html <label> #27241

Closed
@jpduckwo

Description

@jpduckwo

Feature Description

Add an input property to MatLabel that changes the use of <label> into a basic div element without linking it to a control. Perhaps it could be implemented as:

<mat-form-field>
  <mat-label [displayOnly]="true">The label</mat-label>
  <non-labelable-form-control/>
</mat-form-field>

Use Case

When using form fields with standard 'labelable' form elements such as <input> and <select> and using a <mat-label> to label the field, the HTML specification for the <label for="x"> works very nicely. However, there are times when non-standard form elements are desirable to use, such as <mat-select> with html formatted options, or other custom form fields that you might build yourself. In these cases when you use the <mat-label> element, the resulting <label for="x"> generates a page error with the violation:

Incorrect use of <label for=FORM_ELEMENT>

image

You can leave out <mat-label> to work around this, however, it is a better user experience to have the floating label and to also have these form fields match the appearance and behaviour of the other fields in a form.

Metadata

Metadata

Assignees

Labels

AccessibilityThis issue is related to accessibility (a11y)P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: material/form-fieldarea: material/select

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions