Skip to content

Commit b28bade

Browse files
feat(cdk/focus-trap) Backwards compatible factory create method
Optionally accept a boolean instead of a ConfigurableFocusTrapConfig object in the ConfigurableFocusTrapFactory create method, so that it is backwards compatible with FocusTrapFactory create. This will enable apps to turn on the new functionality with {provide: FocusTrapFactory, useClass: ConfigurableFocusTrapFactory}.
1 parent dfb3e05 commit b28bade

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export class ConfigurableFocusTrapConfig<D = any> {
9+
export class ConfigurableFocusTrapConfig {
1010
defer: boolean = false;
1111
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ export class ConfigurableFocusTrapFactory {
4141
/**
4242
* Creates a focus-trapped region around the given element.
4343
* @param element The element around which focus will be trapped.
44-
* @param deferCaptureElements Defers the creation of focus-capturing elements to be done
45-
* manually by the user.
44+
* @param config The config object. Can also be a boolean representing
45+
* ConfigurableFocusTrapConfig.defer, for backwards compatibility with
46+
* the deprecated FocusTrapFactory create method.
4647
* @returns The created focus trap instance.
4748
*/
48-
create(element: HTMLElement, config: ConfigurableFocusTrapConfig =
49+
create(element: HTMLElement, config: ConfigurableFocusTrapConfig | boolean =
4950
new ConfigurableFocusTrapConfig()): ConfigurableFocusTrap {
51+
let configObject: ConfigurableFocusTrapConfig;
52+
if (typeof config === "boolean") {
53+
configObject = new ConfigurableFocusTrapConfig();
54+
configObject.defer = config;
55+
} else {
56+
configObject = config;
57+
}
5058
return new ConfigurableFocusTrap(
5159
element, this._checker, this._ngZone, this._document, this._focusTrapManager,
52-
this._inertStrategy, config);
60+
this._inertStrategy, configObject);
5361
}
5462
}

0 commit comments

Comments
 (0)