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): update focus trap attrs to camel case #6799 #6960

Merged
merged 7 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cdk/a11y/focus-trap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ class FocusTrapWithBindings {
<div cdkTrapFocus>
<input>
<button>before</button>
<button id="first" cdk-focus-region-start></button>
<button id="middle" cdk-focus-initial></button>
<button id="last" cdk-focus-region-end></button>
<button id="first" cdkFocusRegionStart></button>
<button id="middle" cdkFocusInitial></button>
<button id="last" cdkFocusRegionEnd></button>
<button>after</button>
<input>
</div>
Expand Down
19 changes: 15 additions & 4 deletions src/cdk/a11y/focus-trap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,19 @@ export class FocusTrap {
if (!this._platform.isBrowser) {
return null;
}

// Contains the deprecated version of selector, for temporary backwards comparability.
let markers = this._element.querySelectorAll(`[cdk-focus-region-${bound}], ` +
`[cdk-focus-${bound}]`) as NodeListOf<HTMLElement>;
`[cdkFocusRegion${bound}], ` +
`[cdk-focus-${name}]`) as NodeListOf<HTMLElement>;
Copy link
Contributor

Choose a reason for hiding this comment

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

name should be bound


for (let i = 0; i < markers.length; i++) {
if (markers[i].hasAttribute(`cdk-focus-${bound}`)) {
console.warn(`Found use of deprecated attribute 'cdk-focus-${bound}',` +
` use 'cdk-focus-region-${bound}' instead.`, markers[i]);
` use 'cdkFocusRegion${name}' instead.`, markers[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

name should be bound

} else if (markers[i].hasAttribute(`cdk-focus-region-${bound}`)) {
console.warn(`Found use of deprecated attribute 'cdk-focus-region-${bound}',` +
` use 'cdkFocusRegion${name}' instead.`, markers[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

name should be bound

}
}

Expand All @@ -175,8 +179,15 @@ export class FocusTrap {
if (!this._platform.isBrowser) {
return false;
}

// Contains the deprecated version of selector, for temporary backwards comparability.
const redirectToElement = this._element.querySelector(`[cdk-focus-initial], ` +
`[cdkFocusInitial]`) as HTMLElement;

const redirectToElement = this._element.querySelector('[cdk-focus-initial]') as HTMLElement;
if (this._element.hasAttribute(`cdk-focus-initial`)) {
console.warn(`Found use of deprecated attribute 'cdk-focus-initial',` +
` use 'cdkFocusInitial' instead.`, this._element);
}

if (redirectToElement) {
redirectToElement.focus();
Expand Down
6 changes: 3 additions & 3 deletions src/demo-app/drawer/drawer-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ <h2>Drawer with focus attributes</h2>
<mat-drawer #focusDrawer>
<mat-nav-list>
<a mat-list-item routerLink>Link</a>
<a mat-list-item routerLink cdk-focus-region-start>Focus region start</a>
<a mat-list-item routerLink cdkFocusRegionStart>Focus region start</a>
<a mat-list-item routerLink>Link</a>
<a mat-list-item routerLink cdk-focus-initial>Initially focused</a>
<a mat-list-item routerLink cdk-focus-region-end>Focus region end</a>
<a mat-list-item routerLink cdkFocusInitial>Initially focused</a>
<a mat-list-item routerLink cdkFocusRegionEnd>Focus region end</a>
<a mat-list-item routerLink>Link</a>
</mat-nav-list>
</mat-drawer>
Expand Down