Skip to content

feat(cdk/focus-trap) Backwards compatible factory create method #18336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/cdk/a11y/focus-trap/configurable-focus-trap-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/

export class ConfigurableFocusTrapConfig<D = any> {
/**
* Configuration for creating a ConfigurableFocusTrap.
*/
export class ConfigurableFocusTrapConfig {
/**
* Whether to defer the creation of FocusTrap elements to be
* done manually by the user. Default is to create them
* automatically.
*/
defer: boolean = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have docs on the class and the defer property since it's not immediately obvious what deferring means in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just a request for adding comments or API docs? It looks like this Class isn't in the API docs since it wasn't added to the public API in

export * from './focus-trap/configurable-focus-trap';
export * from './focus-trap/event-listener-inert-strategy';
export * from './focus-trap/focus-trap';
export * from './focus-trap/configurable-focus-trap-factory';
export * from './focus-trap/focus-trap-inert-strategy';

}
}
22 changes: 18 additions & 4 deletions src/cdk/a11y/focus-trap/configurable-focus-trap-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,28 @@ export class ConfigurableFocusTrapFactory {
/**
* Creates a focus-trapped region around the given element.
* @param element The element around which focus will be trapped.
* @param deferCaptureElements Defers the creation of focus-capturing elements to be done
* manually by the user.
* @param config The focus trap configuration.
* @returns The created focus trap instance.
*/
create(element: HTMLElement, config: ConfigurableFocusTrapConfig =
create(element: HTMLElement, config?: ConfigurableFocusTrapConfig): ConfigurableFocusTrap;

/**
* @deprecated Pass a config object instead of the `deferCaptureElements` flag.
* @breaking-change 11.0.0
*/
create(element: HTMLElement, deferCaptureElements: boolean): ConfigurableFocusTrap;

create(element: HTMLElement, config: ConfigurableFocusTrapConfig | boolean =
new ConfigurableFocusTrapConfig()): ConfigurableFocusTrap {
let configObject: ConfigurableFocusTrapConfig;
if (typeof config === 'boolean') {
configObject = new ConfigurableFocusTrapConfig();
configObject.defer = config;
} else {
configObject = config;
}
return new ConfigurableFocusTrap(
element, this._checker, this._ngZone, this._document, this._focusTrapManager,
this._inertStrategy, config);
this._inertStrategy, configObject);
}
}
1 change: 1 addition & 0 deletions tools/public_api_guard/cdk/a11y.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export declare class ConfigurableFocusTrap extends FocusTrap implements ManagedF
export declare class ConfigurableFocusTrapFactory {
constructor(_checker: InteractivityChecker, _ngZone: NgZone, _focusTrapManager: FocusTrapManager, _document: any, _inertStrategy?: FocusTrapInertStrategy);
create(element: HTMLElement, config?: ConfigurableFocusTrapConfig): ConfigurableFocusTrap;
create(element: HTMLElement, deferCaptureElements: boolean): ConfigurableFocusTrap;
static ɵfac: i0.ɵɵFactoryDef<ConfigurableFocusTrapFactory>;
static ɵprov: i0.ɵɵInjectableDef<ConfigurableFocusTrapFactory>;
}
Expand Down