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(focus-trap): add the ability to specify a focus target #1752

Merged
merged 1 commit into from
Nov 14, 2016

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Nov 6, 2016

Adds the ability to specify an element that should take precedence over other focusable elements inside of a focus trap.

Fixes #1468.

Note: @jelbourn we discussed that we should have separate start and end directives, which we'd query via @ContentChild or @ViewChild, however I wasn't able to get it working. I was testing with the dialog demo and I think that either the element being nested in multiple other components is breaking it, or the portal (which is used to inject the dialog content) isn't working properly. I've also tried injecting the focus trap into a focus target directive, but it didn't work either.

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 6, 2016
@@ -47,6 +49,12 @@ export class FocusTrap {
return root;
}

let focusTarget = root.querySelector(FOCUS_TARGET_SELECTOR) as HTMLElement;
Copy link
Member

Choose a reason for hiding this comment

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

We don't want to call querySelector here- this method is used recursively, you would would potentially end up calling querySelector many times. This should happen outside of the recursive method.

@@ -1,6 +1,8 @@
import {Component, ViewEncapsulation, ViewChild, ElementRef} from '@angular/core';
import {InteractivityChecker} from './interactivity-checker';

/** Selector for nodes that should have a higher priority when looking for focus targets. */
const FOCUS_TARGET_SELECTOR = '[md-focus-target]';
Copy link
Member

Choose a reason for hiding this comment

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

I'd still like to have separate md-focus-start and md-focus-end attributes, even if they're not directives. With only one attribute, users either have to specify it exactly zero times or more than one time- a user just trying to set where the focus should start would also inadvertently be setting where the focus should wrap backwards to.

@crisbeto
Copy link
Member Author

crisbeto commented Nov 8, 2016

Updated to address the comments.

Adds the ability to specify an element that should take precedence over other focusable elements inside of a focus trap.

Fixes angular#1468.
@jelbourn
Copy link
Member

LGTM

Could you also update the dialog README with this?
(can be in a separate PR)

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels Nov 12, 2016
@kara kara merged commit 72ac7a0 into angular:master Nov 14, 2016
@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 6, 2019
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide way to set focus target when opening dialog
4 participants