From 0b931ea8a4d412f819ba139ac9fd5620464e4e05 Mon Sep 17 00:00:00 2001 From: crisbeto Date: Wed, 28 Mar 2018 21:18:44 +0200 Subject: [PATCH] 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. --- src/cdk/a11y/focus-trap/focus-trap.ts | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/cdk/a11y/focus-trap/focus-trap.ts b/src/cdk/a11y/focus-trap/focus-trap.ts index c80dc33c2b9a..8dbf83827aae 100644 --- a/src/cdk/a11y/focus-trap/focus-trap.ts +++ b/src/cdk/a11y/focus-trap/focus-trap.ts @@ -146,12 +146,15 @@ export class FocusTrap { `[cdk-focus-${bound}]`) as NodeListOf; for (let i = 0; i < markers.length; i++) { + // @deletion-target 7.0.0 if (markers[i].hasAttribute(`cdk-focus-${bound}`)) { - console.warn(`Found use of deprecated attribute 'cdk-focus-${bound}',` + - ` use 'cdkFocusRegion${bound}' instead.`, markers[i]); + console.warn(`Found use of deprecated attribute 'cdk-focus-${bound}', ` + + `use 'cdkFocusRegion${bound}' instead. The deprecated ` + + `attribute will be removed in 7.0.0.`, markers[i]); } else if (markers[i].hasAttribute(`cdk-focus-region-${bound}`)) { - console.warn(`Found use of deprecated attribute 'cdk-focus-region-${bound}',` + - ` use 'cdkFocusRegion${bound}' instead.`, markers[i]); + console.warn(`Found use of deprecated attribute 'cdk-focus-region-${bound}', ` + + `use 'cdkFocusRegion${bound}' instead. The deprecated attribute ` + + `will be removed in 7.0.0.`, markers[i]); } } @@ -171,12 +174,14 @@ export class FocusTrap { 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) { + // @deletion-target 7.0.0 + if (redirectToElement.hasAttribute(`cdk-focus-initial`)) { + console.warn(`Found use of deprecated attribute 'cdk-focus-initial', ` + + `use 'cdkFocusInitial' instead. The deprecated attribute ` + + `will be removed in 7.0.0`, redirectToElement); + } + redirectToElement.focus(); return true; }