UNPKG

7.01 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { BooleanInput } from './boolean-property';
9import { AfterContentInit, ElementRef, NgZone, OnDestroy, DoCheck, SimpleChanges, OnChanges } from '@angular/core';
10import { InteractivityChecker } from './interactivity-checker';
11/**
12 * Class that allows for trapping focus within a DOM element.
13 *
14 * This class currently uses a relatively simple approach to focus trapping.
15 * It assumes that the tab order is the same as DOM order, which is not necessarily true.
16 * Things like `tabIndex > 0`, flex `order`, and shadow roots can cause the two to misalign.
17 *
18 * @deprecated Use `ConfigurableFocusTrap` instead.
19 * @breaking-change for 11.0.0 Remove this class.
20 */
21import * as ɵngcc0 from '@angular/core';
22export declare class FocusTrap {
23 readonly _element: HTMLElement;
24 private _checker;
25 readonly _ngZone: NgZone;
26 readonly _document: Document;
27 private _startAnchor?;
28 private _endAnchor?;
29 private _hasAttached;
30 protected startAnchorListener: () => boolean;
31 protected endAnchorListener: () => boolean;
32 /** Whether the focus trap is active. */
33 get enabled(): boolean;
34 set enabled(value: boolean);
35 protected _enabled: boolean;
36 constructor(_element: HTMLElement, _checker: InteractivityChecker, _ngZone: NgZone, _document: Document, deferAnchors?: boolean);
37 /** Destroys the focus trap by cleaning up the anchors. */
38 destroy(): void;
39 /**
40 * Inserts the anchors into the DOM. This is usually done automatically
41 * in the constructor, but can be deferred for cases like directives with `*ngIf`.
42 * @returns Whether the focus trap managed to attach successfuly. This may not be the case
43 * if the target element isn't currently in the DOM.
44 */
45 attachAnchors(): boolean;
46 /**
47 * Waits for the zone to stabilize, then either focuses the first element that the
48 * user specified, or the first tabbable element.
49 * @returns Returns a promise that resolves with a boolean, depending
50 * on whether focus was moved successfully.
51 */
52 focusInitialElementWhenReady(): Promise<boolean>;
53 /**
54 * Waits for the zone to stabilize, then focuses
55 * the first tabbable element within the focus trap region.
56 * @returns Returns a promise that resolves with a boolean, depending
57 * on whether focus was moved successfully.
58 */
59 focusFirstTabbableElementWhenReady(): Promise<boolean>;
60 /**
61 * Waits for the zone to stabilize, then focuses
62 * the last tabbable element within the focus trap region.
63 * @returns Returns a promise that resolves with a boolean, depending
64 * on whether focus was moved successfully.
65 */
66 focusLastTabbableElementWhenReady(): Promise<boolean>;
67 /**
68 * Get the specified boundary element of the trapped region.
69 * @param bound The boundary to get (start or end of trapped region).
70 * @returns The boundary element.
71 */
72 private _getRegionBoundary;
73 /**
74 * Focuses the element that should be focused when the focus trap is initialized.
75 * @returns Whether focus was moved successfully.
76 */
77 focusInitialElement(): boolean;
78 /**
79 * Focuses the first tabbable element within the focus trap region.
80 * @returns Whether focus was moved successfully.
81 */
82 focusFirstTabbableElement(): boolean;
83 /**
84 * Focuses the last tabbable element within the focus trap region.
85 * @returns Whether focus was moved successfully.
86 */
87 focusLastTabbableElement(): boolean;
88 /**
89 * Checks whether the focus trap has successfully been attached.
90 */
91 hasAttached(): boolean;
92 /** Get the first tabbable element from a DOM subtree (inclusive). */
93 private _getFirstTabbableElement;
94 /** Get the last tabbable element from a DOM subtree (inclusive). */
95 private _getLastTabbableElement;
96 /** Creates an anchor element. */
97 private _createAnchor;
98 /**
99 * Toggles the `tabindex` of an anchor, based on the enabled state of the focus trap.
100 * @param isEnabled Whether the focus trap is enabled.
101 * @param anchor Anchor on which to toggle the tabindex.
102 */
103 private _toggleAnchorTabIndex;
104 /**
105 * Toggles the`tabindex` of both anchors to either trap Tab focus or allow it to escape.
106 * @param enabled: Whether the anchors should trap Tab.
107 */
108 protected toggleAnchors(enabled: boolean): void;
109 /** Executes a function when the zone is stable. */
110 private _executeOnStable;
111}
112/**
113 * Factory that allows easy instantiation of focus traps.
114 * @deprecated Use `ConfigurableFocusTrapFactory` instead.
115 * @breaking-change for 11.0.0 Remove this class.
116 */
117export declare class FocusTrapFactory {
118 private _checker;
119 private _ngZone;
120 private _document;
121 constructor(_checker: InteractivityChecker, _ngZone: NgZone, _document: any);
122 /**
123 * Creates a focus-trapped region around the given element.
124 * @param element The element around which focus will be trapped.
125 * @param deferCaptureElements Defers the creation of focus-capturing elements to be done
126 * manually by the user.
127 * @returns The created focus trap instance.
128 */
129 create(element: HTMLElement, deferCaptureElements?: boolean): FocusTrap;
130 static ɵfac: ɵngcc0.ɵɵFactoryDef<FocusTrapFactory, never>;
131}
132/** Directive for trapping focus within a region. */
133export declare class FocusTrapDirective implements OnDestroy, AfterContentInit, OnChanges, DoCheck {
134 private _elementRef;
135 private _focusTrapFactory;
136 private _document;
137 /** Underlying FocusTrap instance. */
138 focusTrap: FocusTrap;
139 /** Previously focused element to restore focus to upon destroy when using autoCapture. */
140 private _previouslyFocusedElement;
141 /** Whether the focus trap is active. */
142 get enabled(): boolean;
143 set enabled(value: boolean);
144 /**
145 * Whether the directive should automatically move focus into the trapped region upon
146 * initialization and return focus to the previous activeElement upon destruction.
147 */
148 get autoCapture(): boolean;
149 set autoCapture(value: boolean);
150 private _autoCapture;
151 constructor(_elementRef: ElementRef<HTMLElement>, _focusTrapFactory: FocusTrapFactory, _document: any);
152 ngOnDestroy(): void;
153 ngAfterContentInit(): void;
154 ngDoCheck(): void;
155 ngOnChanges(changes: SimpleChanges): void;
156 private _captureFocus;
157 static ngAcceptInputType_enabled: BooleanInput;
158 static ngAcceptInputType_autoCapture: BooleanInput;
159 static ɵfac: ɵngcc0.ɵɵFactoryDef<FocusTrapDirective, never>;
160 static ɵdir: ɵngcc0.ɵɵDirectiveDefWithMeta<FocusTrapDirective, "[focusTrap]", ["focusTrap"], { "enabled": "cdkTrapFocus"; "autoCapture": "cdkTrapFocusAutoCapture"; }, {}, never>;
161}
162
163//# sourceMappingURL=focus-trap.d.ts.map
\No newline at end of file