All files / lib/internal/modal-overlay/sidebar-overlay-container sidebar-overlay-container.component.ts

98.43% Statements 63/64
84.61% Branches 11/13
100% Functions 7/7
98.43% Lines 63/64

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 651x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 7x 7x 91x 91x 7x 7x 1x 1x 5x 5x 5x 5x 5x 5x 5x 1x 1x 5x 65x 65x   65x 5x 5x 5x 1x  
import { Component, EventEmitter, HostBinding } from '@angular/core';
 
import { getKeyboardFocusableElements } from '../../../utils/internal-utils';
 
import { ModalConfig } from '../modal-overlay-container.service';
 
@Component({
  selector: 'gc-sidebar-modal-overlay-container',
  template: '',
  styleUrls: ['./sidebar-overlay-container.component.css'],
})
export class SidebarOverlayContainerComponent {
  @HostBinding('class.gc-modal-error')
  public _errorType = false;
 
  @HostBinding('class.gc-modal-inactive')
  public _inactive = false;
 
  @HostBinding('style.top.px')
  public _offsetTop = 0;
 
  constructor(private config: ModalConfig) {
    this._errorType = config.type === 'error';
    this._offsetTop = this.config.offsetTop ? this.config.offsetTop : 0;
  }
}
 
export class SidebarOverlayRef {
  public readonly onClosed: EventEmitter<void> = new EventEmitter<void>();
 
  private _disabledElements: Map<Element, string | null> = new Map<
    Element,
    string | null
  >();
 
  private focusNode: HTMLElement | null;
 
  constructor() {
    this.focusNode = document.activeElement as HTMLElement;
    getKeyboardFocusableElements(document.body).forEach(el => {
      this._disabledElements.set(el, el.getAttribute('tabindex'));
      el.setAttribute('tabindex', '-1');
    });
  }
 
  public close(): void {
    this.resetTabIndex();
    if (this.focusNode !== null) {
      this.focusNode.focus();
    }
 
    this.onClosed.next();
  }
 
  private resetTabIndex() {
    this._disabledElements.forEach((v, k) => {
      if (v === null) {
        k.removeAttribute('tabindex');
      } else {
        k.setAttribute('tabindex', v);
      }
    });
  }
}