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(dialog): add ariaLabel and focusOnOpen config options #6558

Merged
merged 1 commit into from
Nov 20, 2017

Conversation

crisbeto
Copy link
Member

Based on the discussion on #6360 (comment), these changes add the ability to set the aria-label of a dialog, as well as the element that should be focus when the dialog is opened.

@crisbeto crisbeto added Accessibility This issue is related to accessibility (a11y) pr: needs review labels Aug 20, 2017
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 20, 2017
* Selector for an element to be focused when the dialog is opened. If omitted or the
* element is not found, the dialog will focus the first focusable element.
*/
focusOnOpen?: string | null = null;
Copy link
Member

Choose a reason for hiding this comment

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

With this API, it's not immediately clear what selector you'd set here to focus the root dialog element.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm not sure how we could remedy that. Perhaps supporting :host to align with Angular?

Copy link
Member

Choose a reason for hiding this comment

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

Is there a strong reason to use a selector at all here since the focus trap already supports marking where you want the focus to start? The main thing that's missing is being able to focus the root element, which could just be a boolean.

Copy link
Member Author

Choose a reason for hiding this comment

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

My reasoning to go for a selector instead of the boolean was to make it more flexible so we don't have to tweak it if somebody wants to focus something different from the container. E.g. this allows for the selector to be constructed at runtime, whereas the focus trap attribute needs to be set in advance.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe two properties, then? Something like focusChild for selector and focusRoot?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I'm iffy about having two flags that do more or less the same. What about typing it something like 'root' | string | null. That way it should show up in docs and IDEs that root is a special option.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not a big fan of magic-string APIs. I'd rather go with boolean | string | null, where the boolean means the host element.

What do you think of making this PR just add the ariaLabel and the focusOnOpen for the root element while leaving the content focusing as a responsibility of the focus trap?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good.

@crisbeto
Copy link
Member Author

Rebased and reworked the PR so the focusOnOpen is a boolean @jelbourn. Users can still control what element gets focused first via the cdk-focus-initial attribute.

ariaLabel?: string | null = null;

/** Whether the dialog should focus the first focusable element on open. */
focusOnOpen?: boolean = true;
Copy link
Member

Choose a reason for hiding this comment

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

Coming back again- maybe autoFocus instead? That's what I went with for the focus trap directive

@@ -81,6 +81,11 @@ export class MatDialogConfig<D = any> {
/** ID of the element that describes the dialog. */
ariaDescribedBy?: string | null = null;

/** Aria label to assign to the dialog element */
Copy link
Member

Choose a reason for hiding this comment

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

A thought occurred to me (for a follow-up PR if you agree): to make the focus go to the root dialog element, we can just expose a tabIndex property on the dialog config. If it's 0, then it's the first focusable element. Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that would work since the interactivity checker starts looking from the children. Also we always focus the dialog anyway in order to prevent the user from opening multiple dialogs while animating.

@crisbeto
Copy link
Member Author

Addressed the feedback @jelbourn.

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

Based on the discussion on angular#6360 (comment), these changes add the ability to set the `aria-label` of a dialog, as well as the element that should be focus when the dialog is opened.
@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 Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Accessibility This issue is related to accessibility (a11y) action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants