Skip to content

Commit 0b931ea

Browse files
committed
fix(focus-trap): wrong element being checked when logging deprecation warning
Fixes the host element being checked when logging out the deprecation warning, rather than the deprecated element itself. Also adds deletion targets so we don't miss to deprecate the selectors in 7.0.0. Fixes #10566.
1 parent 0e37d6c commit 0b931ea

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/cdk/a11y/focus-trap/focus-trap.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,15 @@ export class FocusTrap {
146146
`[cdk-focus-${bound}]`) as NodeListOf<HTMLElement>;
147147

148148
for (let i = 0; i < markers.length; i++) {
149+
// @deletion-target 7.0.0
149150
if (markers[i].hasAttribute(`cdk-focus-${bound}`)) {
150-
console.warn(`Found use of deprecated attribute 'cdk-focus-${bound}',` +
151-
` use 'cdkFocusRegion${bound}' instead.`, markers[i]);
151+
console.warn(`Found use of deprecated attribute 'cdk-focus-${bound}', ` +
152+
`use 'cdkFocusRegion${bound}' instead. The deprecated ` +
153+
`attribute will be removed in 7.0.0.`, markers[i]);
152154
} else if (markers[i].hasAttribute(`cdk-focus-region-${bound}`)) {
153-
console.warn(`Found use of deprecated attribute 'cdk-focus-region-${bound}',` +
154-
` use 'cdkFocusRegion${bound}' instead.`, markers[i]);
155+
console.warn(`Found use of deprecated attribute 'cdk-focus-region-${bound}', ` +
156+
`use 'cdkFocusRegion${bound}' instead. The deprecated attribute ` +
157+
`will be removed in 7.0.0.`, markers[i]);
155158
}
156159
}
157160

@@ -171,12 +174,14 @@ export class FocusTrap {
171174
const redirectToElement = this._element.querySelector(`[cdk-focus-initial], ` +
172175
`[cdkFocusInitial]`) as HTMLElement;
173176

174-
if (this._element.hasAttribute(`cdk-focus-initial`)) {
175-
console.warn(`Found use of deprecated attribute 'cdk-focus-initial',` +
176-
` use 'cdkFocusInitial' instead.`, this._element);
177-
}
178-
179177
if (redirectToElement) {
178+
// @deletion-target 7.0.0
179+
if (redirectToElement.hasAttribute(`cdk-focus-initial`)) {
180+
console.warn(`Found use of deprecated attribute 'cdk-focus-initial', ` +
181+
`use 'cdkFocusInitial' instead. The deprecated attribute ` +
182+
`will be removed in 7.0.0`, redirectToElement);
183+
}
184+
180185
redirectToElement.focus();
181186
return true;
182187
}

0 commit comments

Comments
 (0)