From 28a6a7be45d7a7b07da77427d8667a7d80a1539d Mon Sep 17 00:00:00 2001 From: arturovt Date: Mon, 15 Nov 2021 20:10:11 +0200 Subject: [PATCH] perf(cdk/a11y): tree-shake warnings in production --- src/cdk/a11y/focus-trap/focus-trap.ts | 41 +++++++++++++++------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/cdk/a11y/focus-trap/focus-trap.ts b/src/cdk/a11y/focus-trap/focus-trap.ts index f292f41ab634..36577fc0d003 100644 --- a/src/cdk/a11y/focus-trap/focus-trap.ts +++ b/src/cdk/a11y/focus-trap/focus-trap.ts @@ -164,26 +164,28 @@ export class FocusTrap { */ private _getRegionBoundary(bound: 'start' | 'end'): HTMLElement | null { // Contains the deprecated version of selector, for temporary backwards comparability. - let markers = this._element.querySelectorAll( + const markers = this._element.querySelectorAll( `[cdk-focus-region-${bound}], ` + `[cdkFocusRegion${bound}], ` + `[cdk-focus-${bound}]`, ) as NodeListOf; - for (let i = 0; i < markers.length; i++) { - // @breaking-change 8.0.0 - if (markers[i].hasAttribute(`cdk-focus-${bound}`)) { - console.warn( - `Found use of deprecated attribute 'cdk-focus-${bound}', ` + - `use 'cdkFocusRegion${bound}' instead. The deprecated ` + - `attribute will be removed in 8.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. The deprecated attribute ` + - `will be removed in 8.0.0.`, - markers[i], - ); + if (typeof ngDevMode === 'undefined' || ngDevMode) { + for (let i = 0; i < markers.length; i++) { + // @breaking-change 8.0.0 + if (markers[i].hasAttribute(`cdk-focus-${bound}`)) { + console.warn( + `Found use of deprecated attribute 'cdk-focus-${bound}', ` + + `use 'cdkFocusRegion${bound}' instead. The deprecated ` + + `attribute will be removed in 8.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. The deprecated attribute ` + + `will be removed in 8.0.0.`, + markers[i], + ); + } } } @@ -207,7 +209,10 @@ export class FocusTrap { if (redirectToElement) { // @breaking-change 8.0.0 - if (redirectToElement.hasAttribute(`cdk-focus-initial`)) { + if ( + (typeof ngDevMode === 'undefined' || ngDevMode) && + redirectToElement.hasAttribute(`cdk-focus-initial`) + ) { console.warn( `Found use of deprecated attribute 'cdk-focus-initial', ` + `use 'cdkFocusInitial' instead. The deprecated attribute ` +