UNPKG

1.85 kBJavaScriptView 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 */
8/* eslint-disable */
9import { Injectable } from '@angular/core';
10import * as i0 from "@angular/core";
11/** Injectable that ensures only the most recently enabled FocusTrap is active. */
12export class FocusTrapManager {
13 constructor() {
14 // A stack of the FocusTraps on the page. Only the FocusTrap at the
15 // top of the stack is active.
16 this._focusTrapStack = [];
17 }
18 /**
19 * Disables the FocusTrap at the top of the stack, and then pushes
20 * the new FocusTrap onto the stack.
21 */
22 register(focusTrap) {
23 // Dedupe focusTraps that register multiple times.
24 this._focusTrapStack = this._focusTrapStack.filter((ft) => ft !== focusTrap);
25 let stack = this._focusTrapStack;
26 if (stack.length) {
27 stack[stack.length - 1]._disable();
28 }
29 stack.push(focusTrap);
30 focusTrap._enable();
31 }
32 /**
33 * Removes the FocusTrap from the stack, and activates the
34 * FocusTrap that is the new top of the stack.
35 */
36 deregister(focusTrap) {
37 focusTrap._disable();
38 const stack = this._focusTrapStack;
39 const i = stack.indexOf(focusTrap);
40 if (i !== -1) {
41 stack.splice(i, 1);
42 if (stack.length) {
43 stack[stack.length - 1]._enable();
44 }
45 }
46 }
47}
48FocusTrapManager.ɵprov = i0.ɵɵdefineInjectable({ factory: function FocusTrapManager_Factory() { return new FocusTrapManager(); }, token: FocusTrapManager, providedIn: "root" });
49FocusTrapManager.decorators = [
50 { type: Injectable, args: [{ providedIn: 'root' },] }
51];
52//# sourceMappingURL=focus-trap-manager.js.map
\No newline at end of file