Skip to content

Commit d2253b9

Browse files
committed
refactor(cdk/a11y): switch to input transforms
Switches inputs in cdk/a11y to use transforms instead of getters/setters.
1 parent db06fa8 commit d2253b9

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
109
import {_getFocusedElementPierceShadowDom} from '@angular/cdk/platform';
1110
import {DOCUMENT} from '@angular/common';
1211
import {
@@ -21,6 +20,7 @@ import {
2120
DoCheck,
2221
SimpleChanges,
2322
OnChanges,
23+
booleanAttribute,
2424
} from '@angular/core';
2525
import {take} from 'rxjs/operators';
2626
import {InteractivityChecker} from '../interactivity-checker/interactivity-checker';
@@ -413,26 +413,19 @@ export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoC
413413
private _previouslyFocusedElement: HTMLElement | null = null;
414414

415415
/** Whether the focus trap is active. */
416-
@Input('cdkTrapFocus')
416+
@Input({alias: 'cdkTrapFocus', transform: booleanAttribute})
417417
get enabled(): boolean {
418418
return this.focusTrap.enabled;
419419
}
420-
set enabled(value: BooleanInput) {
421-
this.focusTrap.enabled = coerceBooleanProperty(value);
420+
set enabled(value: boolean) {
421+
this.focusTrap.enabled = value;
422422
}
423423

424424
/**
425425
* Whether the directive should automatically move focus into the trapped region upon
426426
* initialization and return focus to the previous activeElement upon destruction.
427427
*/
428-
@Input('cdkTrapFocusAutoCapture')
429-
get autoCapture(): boolean {
430-
return this._autoCapture;
431-
}
432-
set autoCapture(value: BooleanInput) {
433-
this._autoCapture = coerceBooleanProperty(value);
434-
}
435-
private _autoCapture: boolean;
428+
@Input({alias: 'cdkTrapFocusAutoCapture', transform: booleanAttribute}) autoCapture: boolean;
436429

437430
constructor(
438431
private _elementRef: ElementRef<HTMLElement>,

tools/public_api_guard/cdk/a11y.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { AfterContentInit } from '@angular/core';
88
import { AfterViewInit } from '@angular/core';
9-
import { BooleanInput } from '@angular/cdk/coercion';
109
import { ContentObserver } from '@angular/cdk/observers';
1110
import { DoCheck } from '@angular/core';
1211
import { ElementRef } from '@angular/core';
@@ -102,12 +101,15 @@ export class CdkMonitorFocus implements AfterViewInit, OnDestroy {
102101
export class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoCheck {
103102
constructor(_elementRef: ElementRef<HTMLElement>, _focusTrapFactory: FocusTrapFactory,
104103
_document: any);
105-
get autoCapture(): boolean;
106-
set autoCapture(value: BooleanInput);
104+
autoCapture: boolean;
107105
get enabled(): boolean;
108-
set enabled(value: BooleanInput);
106+
set enabled(value: boolean);
109107
focusTrap: FocusTrap;
110108
// (undocumented)
109+
static ngAcceptInputType_autoCapture: unknown;
110+
// (undocumented)
111+
static ngAcceptInputType_enabled: unknown;
112+
// (undocumented)
111113
ngAfterContentInit(): void;
112114
// (undocumented)
113115
ngDoCheck(): void;

0 commit comments

Comments
 (0)