All files / lib/infobox/infobox-container infobox-container.component.ts

95.93% Statements 118/123
100% Branches 14/14
85.71% Functions 6/7
95.93% Lines 118/123

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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 1241x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 1x 1x 8x 106x 106x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 1x 1x 1x           1x 1x 1x 4x 48x 45x 3x 3x 48x 4x 4x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  EventEmitter,
  HostListener,
  Input,
  OnDestroy,
  Output,
  TemplateRef,
  ViewChild,
} from '@angular/core';
 
import { getKeyboardFocusableElements } from '../../utils/internal-utils';
import {
  BadgeItem,
  FocusableElementOwner,
  WidgetKeySet,
} from '../../utils/util.types';
import { createWidgetKeySet } from '../../utils/utilities';
 
import { AutoFocusAreaDirective } from '../../internal/auto-focus-area.directive';
 
import { BadgeItemTemplateContext } from '../../badge-list/badge-list.component';
 
/**
 * Infobox Container component that is a part of the gc-infobox component. Acts as a dropdown container.
 */
@Component({
  selector: 'gc-infobox-container',
  templateUrl: './infobox-container.component.html',
  styleUrls: ['./infobox-container.component.css'],
  standalone: false,
})
export class InfoboxContainerComponent
  implements FocusableElementOwner, OnDestroy
{
  /**
   * Label of the infobox container.
   */
  @Input({ required: true })
  public label = '';
 
  /**
   * Items that will be rendered as badges in the header.
   */
  @Input()
  public badges: readonly BadgeItem[] = [];
 
  /**
   * A template that will be used to render icons within badges.
   */
  @Input()
  public badgeIconProvider?: TemplateRef<BadgeItemTemplateContext>;
 
  /**
   * Hint message that appears within the header.
   */
  @Input()
  public hintTitle = '';
 
  /**
   * Event emitted on close button press.
   */
  @Output()
  public readonly onClose: EventEmitter<void> = new EventEmitter<void>();
 
  /** @ignore */
  @ViewChild(AutoFocusAreaDirective)
  private contentAutoFocusArea?: AutoFocusAreaDirective;
 
  /** @ignore */
  protected readonly _widgetKeys: WidgetKeySet = createWidgetKeySet(
    'gc-infobox-container',
  );
 
  /** @ignore */
  private _disabledElements: Map<Element, string | null> = new Map<
    Element,
    string | null
  >();
 
  constructor() {
    getKeyboardFocusableElements(document.body).forEach(el => {
      this._disabledElements.set(el, el.getAttribute('tabindex'));
      el.setAttribute('tabindex', '-1');
    });
  }
 
  /** @ignore */
  @HostListener('keydown', ['$event'])
  protected onKeyDown(e: KeyboardEvent): void {
    if (e.key === 'Escape') {
      this.onClose.emit();
    }
  }
 
  ngOnDestroy(): void {
    this.resetTabIndex();
  }
 
  /** @ignore */
  public focusChild(): boolean {
    if (!this.contentAutoFocusArea) {
      return false;
    }
    return this.contentAutoFocusArea.focusInitialElement();
  }
 
  /** @ignore */
  private resetTabIndex() {
    this._disabledElements.forEach((v, k) => {
      if (v === null) {
        k.removeAttribute('tabindex');
      } else {
        k.setAttribute('tabindex', v);
      }
    });
  }
}