[6a3a178] | 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 | */
|
---|
| 8 | import { BooleanInput } from '@angular/cdk/coercion';
|
---|
| 9 | import { AfterContentInit, ElementRef, NgZone, OnDestroy, DoCheck, SimpleChanges, OnChanges } from '@angular/core';
|
---|
| 10 | import { InteractivityChecker } from '../interactivity-checker/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 be misaligned.
|
---|
| 17 | *
|
---|
| 18 | * @deprecated Use `ConfigurableFocusTrap` instead.
|
---|
| 19 | * @breaking-change 11.0.0
|
---|
| 20 | */
|
---|
| 21 | import * as ɵngcc0 from '@angular/core';
|
---|
| 22 | export 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 successfully. 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(options?: FocusOptions): 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(options?: FocusOptions): 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(options?: FocusOptions): 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(options?: FocusOptions): boolean;
|
---|
| 78 | /**
|
---|
| 79 | * Focuses the first tabbable element within the focus trap region.
|
---|
| 80 | * @returns Whether focus was moved successfully.
|
---|
| 81 | */
|
---|
| 82 | focusFirstTabbableElement(options?: FocusOptions): boolean;
|
---|
| 83 | /**
|
---|
| 84 | * Focuses the last tabbable element within the focus trap region.
|
---|
| 85 | * @returns Whether focus was moved successfully.
|
---|
| 86 | */
|
---|
| 87 | focusLastTabbableElement(options?: FocusOptions): 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 11.0.0
|
---|
| 116 | */
|
---|
| 117 | export 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.ɵɵFactoryDeclaration<FocusTrapFactory, never>;
|
---|
| 131 | }
|
---|
| 132 | /** Directive for trapping focus within a region. */
|
---|
| 133 | export declare class CdkTrapFocus implements OnDestroy, AfterContentInit, OnChanges, DoCheck {
|
---|
| 134 | private _elementRef;
|
---|
| 135 | private _focusTrapFactory;
|
---|
| 136 | /** Underlying FocusTrap instance. */
|
---|
| 137 | focusTrap: FocusTrap;
|
---|
| 138 | /** Previously focused element to restore focus to upon destroy when using autoCapture. */
|
---|
| 139 | private _previouslyFocusedElement;
|
---|
| 140 | /** Whether the focus trap is active. */
|
---|
| 141 | get enabled(): boolean;
|
---|
| 142 | set enabled(value: boolean);
|
---|
| 143 | /**
|
---|
| 144 | * Whether the directive should automatically move focus into the trapped region upon
|
---|
| 145 | * initialization and return focus to the previous activeElement upon destruction.
|
---|
| 146 | */
|
---|
| 147 | get autoCapture(): boolean;
|
---|
| 148 | set autoCapture(value: boolean);
|
---|
| 149 | private _autoCapture;
|
---|
| 150 | constructor(_elementRef: ElementRef<HTMLElement>, _focusTrapFactory: FocusTrapFactory,
|
---|
| 151 | /**
|
---|
| 152 | * @deprecated No longer being used. To be removed.
|
---|
| 153 | * @breaking-change 13.0.0
|
---|
| 154 | */
|
---|
| 155 | _document: any);
|
---|
| 156 | ngOnDestroy(): void;
|
---|
| 157 | ngAfterContentInit(): void;
|
---|
| 158 | ngDoCheck(): void;
|
---|
| 159 | ngOnChanges(changes: SimpleChanges): void;
|
---|
| 160 | private _captureFocus;
|
---|
| 161 | static ngAcceptInputType_enabled: BooleanInput;
|
---|
| 162 | static ngAcceptInputType_autoCapture: BooleanInput;
|
---|
| 163 | static ɵfac: ɵngcc0.ɵɵFactoryDeclaration<CdkTrapFocus, never>;
|
---|
| 164 | static ɵdir: ɵngcc0.ɵɵDirectiveDeclaration<CdkTrapFocus, "[cdkTrapFocus]", ["cdkTrapFocus"], { "enabled": "cdkTrapFocus"; "autoCapture": "cdkTrapFocusAutoCapture"; }, {}, never>;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | //# sourceMappingURL=focus-trap.d.ts.map |
---|