-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix(focus-trap): update focus trap attrs to camel case #6799 #6960
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
Changes from 2 commits
da9c1ea
d24830d
d47e6c5
506f049
339042b
df5fb46
34e21ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,14 +145,19 @@ export class FocusTrap { | |
* @returns The boundary element. | ||
*/ | ||
private _getRegionBoundary(bound: 'start' | 'end'): HTMLElement | null { | ||
const name = bound.charAt(0).toUpperCase() + bound.slice(1).toLowerCase(); | ||
// 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>; | ||
|
||
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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} 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]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
|
@@ -168,7 +173,14 @@ export class FocusTrap { | |
* @returns Returns whether focus was moved successfuly. | ||
*/ | ||
focusInitialElement(): boolean { | ||
const redirectToElement = this._element.querySelector('[cdk-focus-initial]') as HTMLElement; | ||
// Contains the deprecated version of selector, for temporary backwards comparability. | ||
const redirectToElement = this._element.querySelector(`[cdk-focus-initial], ` + | ||
`[cdkFocusInitial]`) 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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,10 +68,10 @@ <h2>Sidenav with focus attributes</h2> | |
<md-sidenav #focusSidenav> | ||
<md-nav-list> | ||
<a md-list-item routerLink>Link</a> | ||
<a md-list-item routerLink cdk-focus-region-start>Focus region start</a> | ||
<a md-list-item routerLink cdkFocusStart>Focus region start</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<a md-list-item routerLink>Link</a> | ||
<a md-list-item routerLink cdk-focus-initial>Initially focused</a> | ||
<a md-list-item routerLink cdk-focus-region-end>Focus region end</a> | ||
<a md-list-item routerLink cdkFocusInitial>Initially focused</a> | ||
<a md-list-item routerLink cdkFocusEnd>Focus region end</a> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
<a md-list-item routerLink>Link</a> | ||
</md-nav-list> | ||
</md-sidenav> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
should bebound