UNPKG

ngx-bootstrap

Version:
52 lines 1.85 kB
/** * @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 { Injectable } from '@angular/core'; import * as i0 from "@angular/core"; /** Injectable that ensures only the most recently enabled FocusTrap is active. */ export class FocusTrapManager { constructor() { // A stack of the FocusTraps on the page. Only the FocusTrap at the // top of the stack is active. this._focusTrapStack = []; } /** * Disables the FocusTrap at the top of the stack, and then pushes * the new FocusTrap onto the stack. */ register(focusTrap) { // Dedupe focusTraps that register multiple times. this._focusTrapStack = this._focusTrapStack.filter((ft) => ft !== focusTrap); let stack = this._focusTrapStack; if (stack.length) { stack[stack.length - 1]._disable(); } stack.push(focusTrap); focusTrap._enable(); } /** * Removes the FocusTrap from the stack, and activates the * FocusTrap that is the new top of the stack. */ deregister(focusTrap) { focusTrap._disable(); const stack = this._focusTrapStack; const i = stack.indexOf(focusTrap); if (i !== -1) { stack.splice(i, 1); if (stack.length) { stack[stack.length - 1]._enable(); } } } } FocusTrapManager.ɵprov = i0.ɵɵdefineInjectable({ factory: function FocusTrapManager_Factory() { return new FocusTrapManager(); }, token: FocusTrapManager, providedIn: "root" }); FocusTrapManager.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; //# sourceMappingURL=focus-trap-manager.js.map