Skip to content

feat(focus-trap): allow setting initially focused element #4577

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

Merged
merged 4 commits into from
May 19, 2017

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented May 15, 2017

also fix md-nav-list focused item style.

fixes #2224

@mmalerba mmalerba requested a review from jelbourn May 15, 2017 22:52
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 15, 2017
@@ -97,27 +101,47 @@ export class FocusTrap {
this._ngZone.onMicrotaskEmpty.first().subscribe(() => this.focusLastTabbableElement());
}

private _getRegionMarker(marker: 'start' | 'end'): HTMLElement | null {
Copy link
Member

Choose a reason for hiding this comment

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

Add function description? Not immediately clear what a "region marker" is.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of "marker", maybe "boundary element"?

@@ -151,6 +149,7 @@ export class MdListItem implements AfterContentInit {

constructor(private _renderer: Renderer2,
private _element: ElementRef,
private _cdr: ChangeDetectorRef,
Copy link
Member

Choose a reason for hiding this comment

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

Where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nowhere, switched to adding class via renderer


/** Focuses the element that should be focused when the focus trap is initialized. */
focusInitialElement() {
let redirectToElement = this._element.querySelector('[cdk-focus-init]') 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.

Write out initial (to disambiguate from "initialize")?

<button id="first" cdk-focus-start>SAVE</button>
<button id="last" cdk-focus-region-end></button>
<button id="middle" cdk-focus-init></button>
<button id="first" cdk-focus-region-start>SAVE</button>
Copy link
Member

Choose a reason for hiding this comment

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

Why does start come after end here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was already like this, I think the reasoning is to make sure that it's really grabbing the element with the attribute, not just the first or last one. I changed it to something less confusing.

private _getRegionMarker(marker: 'start' | 'end'): HTMLElement | null {
let markers = [
...Array.prototype.slice.call(this._element.querySelectorAll(`[cdk-focus-region-${marker}]`)),
...Array.prototype.slice.call(this._element.querySelectorAll(`[cdk-focus-${marker}]`)),
Copy link
Member

Choose a reason for hiding this comment

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

Add comment explaining what's for backwards compatibility

@mmalerba
Copy link
Contributor Author

comments addressed, PTAL

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

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed pr: needs review labels May 18, 2017
@mmalerba mmalerba added the Accessibility This issue is related to accessibility (a11y) label May 18, 2017
@jelbourn jelbourn merged commit c946631 into angular:master May 19, 2017
@mmalerba mmalerba deleted the focus-trap branch July 31, 2018 21:19
@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 9, 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.

md-sidenav mode="over" focus state
3 participants