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

fix(focus-trap): focus initial element when zone stabilizes #4867

Merged
merged 2 commits into from
Jun 5, 2017

Conversation

crisbeto
Copy link
Member

  • Focuses the first element when the zone stabilizes, instead of when the microtask queue is empty. This avoids issues where the element might be focused before Angular is done doing change detection.
  • Only runs the onStable callback if the zone is unstable.
  • Avoids an extra DOM lookup by combining a couple of selectors.

Fixes #4864.

Note: Since change detection is all being run manually in unit tests, I wasn't able to write a test that would fail properly when we expect it to.

* Focuses the first element when the zone stabilizes, instead of when the microtask queue is empty. This avoids issues where the element might be focused before Angular is done doing change detection.
* Only runs the `onStable` callback if the zone is unstable.
* Avoids an extra DOM lookup by combining a couple of selectors.

Fixes angular#4864.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 29, 2017
...Array.prototype.slice.call(this._element.querySelectorAll(`[cdk-focus-${bound}]`)),
];
// Contains the deprecated version of selector, for temporary backwards comparability.
let markers = this._element.querySelectorAll(`[cdk-focus-region-${bound}], ` +
Copy link
Contributor

Choose a reason for hiding this comment

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

I did this to make sure the new version takes precedence over the deprecated version, idk maybe it was overkill though

Copy link
Member Author

Choose a reason for hiding this comment

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

It's probably overkill since the deprecated and the supported directives do exactly the same.


markers.forEach((el: HTMLElement) => {
Array.prototype.forEach.call(markers, (el: HTMLElement) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

could we do a for of loop here to avoid the weird syntax? or does that have the same issue of not working with NodeList?

Copy link
Member Author

Choose a reason for hiding this comment

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

Loops work fine. Changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually meant the for (let val of iterable) style, but this is fine too

@mmalerba mmalerba added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels May 31, 2017
@mmalerba
Copy link
Contributor

LGTM

@andrewseguin andrewseguin merged commit ce9d253 into angular:master Jun 5, 2017
@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.

md-input doesn't behave correct if initially focused in md-dialog
4 participants