-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(focus-trap): add focus trap module (#5634)
* feat(common): add focus trap module Add focus trap module to follow accessibility Add focus trap directive to modal container * fix(focus-trap): fix moduleWithProviders type issue * feat(focus-trap): update focus-trap code according to last Angular changes * feat(focus-trap): add focus-trap module to build process with nx * fix(lint): disable eslint for focus-trap source files Co-authored-by: Dmitry Danilov <daniloff200@gmail.com>
- Loading branch information
1 parent
51051bd
commit 8bcc900
Showing
31 changed files
with
1,441 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts"], | ||
"extends": [ | ||
"plugin:@nrwl/nx/angular", | ||
"plugin:@angular-eslint/template/process-inline-templates" | ||
], | ||
"parserOptions": { "project": ["src/focus-trap/tsconfig.*?.json"] }, | ||
"rules": { | ||
"@angular-eslint/no-output-on-prefix": 0 | ||
} | ||
}, | ||
{ | ||
"files": ["*.html"], | ||
"extends": ["plugin:@nrwl/nx/angular-template"], | ||
"rules": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# focus-trap | ||
|
||
This library was generated with [Nx](https://nx.dev). | ||
|
||
## Running unit tests | ||
|
||
Run `nx test focus-trap` to execute the unit tests. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* eslint-disable */ | ||
|
||
/** | ||
* Type describing the allowed values for a boolean input. | ||
* @docs-private | ||
*/ | ||
export type BooleanInput = string | boolean | null | undefined; | ||
|
||
/** Coerces a data-bound value (typically a string) to a boolean. */ | ||
export function coerceBooleanProperty(value: any): boolean { | ||
return value != null && `${value}` !== 'false'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* Configuration for creating a ConfigurableFocusTrap. | ||
*/ | ||
|
||
/* eslint-disable */ | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/* eslint-disable */ | ||
|
||
import { DOCUMENT } from '@angular/common'; | ||
import { | ||
Inject, | ||
Injectable, | ||
Optional, | ||
NgZone | ||
} from '@angular/core'; | ||
import { InteractivityChecker } from './interactivity-checker'; | ||
import { ConfigurableFocusTrap } from './configurable-focus-trap'; | ||
import { ConfigurableFocusTrapConfig } from './configurable-focus-trap-config'; | ||
import { FOCUS_TRAP_INERT_STRATEGY, FocusTrapInertStrategy } from './focus-trap-inert-strategy'; | ||
import { EventListenerFocusTrapInertStrategy } from './event-listener-inert-strategy'; | ||
import { FocusTrapManager } from './focus-trap-manager'; | ||
|
||
/** Factory that allows easy instantiation of configurable focus traps. */ | ||
@Injectable({ providedIn: 'root' }) | ||
export class ConfigurableFocusTrapFactory { | ||
private _document: Document; | ||
private _inertStrategy: FocusTrapInertStrategy; | ||
|
||
constructor( | ||
private _checker: InteractivityChecker, | ||
private _ngZone: NgZone, | ||
private _focusTrapManager: FocusTrapManager, | ||
@Inject(DOCUMENT) _document: any, | ||
@Optional() @Inject(FOCUS_TRAP_INERT_STRATEGY) _inertStrategy?: FocusTrapInertStrategy) { | ||
|
||
this._document = _document; | ||
// TODO split up the strategies into different modules, similar to DateAdapter. | ||
this._inertStrategy = _inertStrategy || new EventListenerFocusTrapInertStrategy(); | ||
} | ||
|
||
/** | ||
* Creates a focus-trapped region around the given element. | ||
* @param element The element around which focus will be trapped. | ||
* @param config The focus trap configuration. | ||
* @returns The created focus trap instance. | ||
*/ | ||
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, configObject); | ||
} | ||
} |
Oops, something went wrong.