Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(form-field): expose label content element id for custom controls #18528

Merged
merged 2 commits into from Jul 29, 2020

Conversation

devversion
Copy link
Member

@devversion devversion commented Feb 17, 2020

Currently, the form-field always creates a label element as sibling
to projected form-field controls. For native controls, the label is
associated with the controls using the for attribute.

This doesn't work for custom controls which might not be based
on native controls. e.g. the mat-select. In those cases, the
appropriate aria attributes need to be applied with aria-labelledby
that refers to the label content element.

Since this is a common pattern for custom controls that don't use
native controls, we need to expose the element id for the label content.

Currently we already do this for the select, but just prefixed it with
an underscore. This denotes it as private API while there is obviously a
use-case for exposing this publicly. Best example is how the select needs it.

Note: If we decide to go with that change, the target is usually minor, but it might be worth checking if we could get it into master earlier for our MDC form-field changes.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Feb 17, 2020
@jelbourn jelbourn added the target: minor This PR is targeted for the next minor release label Feb 18, 2020
@devversion devversion force-pushed the refactor/mdc-form-field-label branch 3 times, most recently from c5fa00e to e3101ce Compare February 26, 2020 11:46
@devversion
Copy link
Member Author

@crisbeto @mmalerba Addressed the feedback. Please have another look.

@@ -23,7 +23,7 @@ class MyTel {
@Component({
selector: 'example-tel-input',
template: `
<div [formGroup]="parts">
<div role="group" [formGroup]="parts">
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This is the recommended pattern for grouping multiple inputs: https://www.w3.org/TR/WCAG20-TECHS/ARIA17.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crisbeto do we have this on date-range-input?

Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

guides/creating-a-custom-form-field-control.md Outdated Show resolved Hide resolved
guides/creating-a-custom-form-field-control.md Outdated Show resolved Hide resolved
@devversion
Copy link
Member Author

@mmalerba Addressed your feedback. Thanks!

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Feb 26, 2020
@devversion devversion force-pushed the refactor/mdc-form-field-label branch from 307f446 to db1fafe Compare May 7, 2020 13:31
Currently, the form-field always creates a label element as sibling
to projected form-field controls. For native controls, the label is
associated with the controls using the `for` attribute.

This doesn't work for custom controls which might not be based
on native controls. e.g. the `mat-select`. In those cases, the
appropriate aria attributes need to be applied with `aria-labelledby`
that refers to the label content element.

Since this is a common pattern for custom controls that don't use
native controls, we need to expose the element id for the label content.

Currently we already do this for the select, but just prefixed it with
an underscore. This denotes it as private API while there is obviously a
use-case for exposing this publicly. Best example is how the select
_needs_ it.
Improves the accessibility for the control that is built as part
of the custom form-field control guide.
@devversion devversion force-pushed the refactor/mdc-form-field-label branch from db1fafe to 83d363e Compare June 22, 2020 06:15
@jelbourn jelbourn merged commit 23818f5 into angular:master Jul 29, 2020
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants