Skip to content

Commit 81a32a4

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 81a32a4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 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,9 +174,11 @@ 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+
// @deletion-target 7.0.0
178+
if (redirectToElement.hasAttribute(`cdk-focus-initial`)) {
179+
console.warn(`Found use of deprecated attribute 'cdk-focus-initial', ` +
180+
`use 'cdkFocusInitial' instead. The deprecated attribute ` +
181+
`will be removed 7.0.0`, redirectToElement);
177182
}
178183

179184
if (redirectToElement) {

0 commit comments

Comments
 (0)