All files / lib/ext-search/ext-search-menu-button ext-search-menu-button.component.ts

97.95% Statements 96/98
95.65% Branches 22/23
100% Functions 16/16
97.95% Lines 96/98

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 991x 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 1x 1x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 1x 1x 1x 1x 3x 3x 3x     3x 1x 1x 1x 1x 1x 1x 1x 1x 8x 3x 8x 8x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  ViewChild,
} from '@angular/core';
 
import {
  FocusableElementOwner,
  Item,
  Key,
  WidgetKeySet,
} from '../../utils/util.types';
import { createWidgetKeySet } from '../../utils/utilities';
 
import { MenuComponent } from '../../internal/menu/menu.component';
 
import { BaseExtSearchComponent } from '../base-ext-search/base-ext-search-field.component';
import { BaseExtSearchSingleFieldComponent } from '../base-ext-search/base-ext-search-single-field.component';
 
@Component({
  selector: 'gc-ext-search-menu-button',
  templateUrl: './ext-search-menu-button.component.html',
  styleUrls: ['./ext-search-menu-button.component.css'],
  providers: [
    {
      provide: BaseExtSearchComponent,
      useExisting: ExtSearchMenuButtonComponent,
    },
  ],
  standalone: false,
})
export class ExtSearchMenuButtonComponent<MenuItem extends Item = Item>
  extends BaseExtSearchSingleFieldComponent
  implements FocusableElementOwner
{
  /**
   * Items to display in the menu button.
   */
  @Input({ required: true })
  public items: readonly MenuItem[] = [];
 
  /** Currently selected item. */
  @Input({ required: true })
  public selectedItem?: Key;
 
  /** Label of the menu button. */
  @Input()
  buttonLabel = '';
 
  /**
   * Fires upon selecting an item from the menu (even the already selected one).
   */
  @Output()
  public readonly onMenuAction: EventEmitter<MenuItem> =
    new EventEmitter<MenuItem>();
 
  /** @ignore */
  @ViewChild('menuButton')
  private menuButton?: ElementRef<HTMLButtonElement>;
 
  /** @ignore */
  @ViewChild(MenuComponent)
  private menu?: MenuComponent<MenuItem>;
 
  /** @ignore */
  protected override readonly _widgetKeys: WidgetKeySet = createWidgetKeySet(
    'gc-ext-search-menu-button',
  );
 
  /** @ignore */
  public override focusChild(): boolean {
    if (this.menuButton) {
      this.menuButton.nativeElement.focus();
      return true;
    }
    return false;
  }
 
  /** @ignore */
  protected onItemSelection(item: MenuItem): void {
    this.onMenuAction.emit(item);
  }
 
  /** @ignore */
  protected handleBlurEvent(): void {
    if (!this.menu?.menuOpen) {
      this.onFocusLeft.emit();
    }
  }
}