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

100% Statements 91/91
100% Branches 8/8
100% Functions 5/5
100% Lines 91/91

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 921x 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 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 413x 1x 1x 1x 1x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  ChangeDetectionStrategy,
  Component,
  TemplateRef,
  input,
  output,
  viewChild,
} from '@angular/core';
 
import { HasFocusEvent } from '../utils/event.types';
import { FocusableElementOwner, Item } from '../utils/util.types';
 
import { ButtonComponent } from '../button/button.component';
 
/**
 * A Menu Button element that opens a menu with multiple items as options.
 */
@Component({
  selector: 'gc-menu-button',
  templateUrl: './menu-button.component.html',
  styleUrls: ['./menu-button.component.css'],
  changeDetection: ChangeDetectionStrategy.Eager,
  standalone: false,
})
export class MenuButtonComponent implements FocusableElementOwner {
  /**
   * Action that is fired when an menu item is pressed.
   */
  public readonly onAction = output<Item>();
 
  /**
   * Label that is used for accessibility purposes.
   */
  public readonly label = input('');
 
  /**
   * Alternative tooltip text if it has to differ to the label
   */
  public readonly tooltipText = input<string>();
 
  /**
   * All items that will appear in the menu.
   */
  public readonly menuItems = input<readonly Item[]>([]);
 
  /**
   * All items in the menu that are disabled.
   */
  public readonly disabledItems = input<ReadonlySet<string>>(new Set());
 
  /**
   * Decides on which side of the menu button the menu is going to appear.
   */
  public readonly alignment = input<'start' | 'end' | 'auto'>('end');
 
  /**
   * @ignore
   * Overrides the default menu button tabindex value.
   */
  public readonly _tabIndexOverride = input<number>();
 
  /** Optional icon provider to use for menu-items */
  public readonly menuItemIconProvider =
    input<TemplateRef<{ $implicit: Item }>>();
 
  /**
   * If set to true the button state is set to disabled which means that it is no longer clickable.
   */
  public readonly disabled = input(false);
 
  /**
   * Fires when focus status has changed.
   */
  public readonly onFocusChange = output<HasFocusEvent>();
 
  /**
   * @ignore
   */
  private readonly menuButton = viewChild.required('menubutton', {
    read: ButtonComponent,
  });
 
  public focusChild(): boolean {
    return this.menuButton().focusChild();
  }
}