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

100% Statements 99/99
100% Branches 8/8
100% Functions 4/4
100% Lines 99/99

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 1001x 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 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 365x 1x 1x 1x 1x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  EventEmitter,
  Input,
  Output,
  TemplateRef,
  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'],
  standalone: false,
})
export class MenuButtonComponent implements FocusableElementOwner {
  /**
   * Action that is fired when an menu item is pressed.
   */
  @Output()
  public readonly onAction: EventEmitter<Item> = new EventEmitter<Item>();
 
  /**
   * Label that is used for accessibility purposes.
   */
  @Input()
  public label = '';
 
  /**
   * Alternative tooltip text if it has to differ to the label
   */
  @Input()
  public tooltipText?: string;
 
  /**
   * All items that will appear in the menu.
   */
  @Input()
  public menuItems: readonly Item[] = [];
 
  /**
   * All items in the menu that are disabled.
   */
  @Input()
  public disabledItems: ReadonlySet<string> = new Set();
 
  /**
   * Decides on which side of the menu button the menu is going to appear.
   */
  @Input()
  public alignment: 'start' | 'end' | 'auto' = 'end';
 
  /**
   * @ignore
   * Overrides the default menu button tabindex value.
   */
  @Input()
  public _tabIndexOverride?: number;
 
  /** Optional icon provider to use for menu-items */
  @Input()
  public menuItemIconProvider?: TemplateRef<unknown>;
 
  /**
   * If set to true the button state is set to disabled which means that it is no longer clickable.
   */
  @Input()
  public disabled = false;
 
  /**
   * Fires when focus status has changed.
   */
  @Output()
  public readonly onFocusChange: EventEmitter<HasFocusEvent> =
    new EventEmitter<HasFocusEvent>();
 
  /**
   * @ignore
   */
  @ViewChild('menubutton', { read: ButtonComponent })
  private menuButton!: ButtonComponent;
 
  public focusChild(): boolean {
    return this.menuButton.focusChild();
  }
}