All files / lib/internal/wizard-stepper/wizard-stepper-horizontal wizard-stepper-horizontal.component.ts

97.59% Statements 162/166
96.55% Branches 28/29
89.47% Functions 17/19
97.59% Lines 162/166

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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 1671x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 19x 2502x 2502x 2502x 19x 19x 27x 27x 19x 19x 442x 442x 442x 19x 19x 19x 19x 19x 19x 19x 332x 332x 19x 19x 19x 221x 221x 221x 221x 221x 221x 85x 85x 221x 19x 19x 19x 19x 19x 19x 1x 1x 1x 1x 1x     1x 1x 19x 19x 1x 1x 19x 19x 1x 1x 1989x 1989x 1x 1x     1x 1x 221x 221x 221x 221x 221x 221x 221x 221x 221x 1x 1x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 1x 1x 1x 4x 4x 4x 1x 1x 1x 14x 14x 14x 14x 14x 14x 14x 14x 14x 1x  
/*******************************************************************************
 * Copyright bei
 * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
 *
 *******************************************************************************/
import {
  Component,
  ElementRef,
  EventEmitter,
  Input,
  Output,
  ViewChild,
} from '@angular/core';
 
import { IndexedItem, textToLine } from '../../../utils/internal-utils';
import { Item, Key, WidgetKeySet } from '../../../utils/util.types';
import { createWidgetKeySet } from '../../../utils/utilities';
 
import {
  BasePickerComponent,
  KeyFocusTarget,
} from '../../../picker/base-picker.component';
import { SelectionEvent } from '../../listbox.directive';
 
@Component({
  selector: 'gc-wizard-stepper-horizontal',
  templateUrl: './wizard-stepper-horizontal.component.html',
  styleUrls: [
    './../../../utils/styles/reset-button.css',
    './wizard-stepper-horizontal.component.css',
  ],
})
export class WizardStepperHorizontalComponent extends BasePickerComponent<
  Item,
  Item
> {
  /** Inform about the change of the selection state */
  @Output()
  public readonly valueChange: EventEmitter<Item> = new EventEmitter<Item>();
 
  @Input()
  public selectableItems: readonly Item[] = [];
 
  @Input()
  public controlledId = '';
 
  @ViewChild('button')
  public button!: ElementRef<HTMLButtonElement>;
 
  @ViewChild('wizardStepperContainer')
  private containerElement!: ElementRef<HTMLDivElement>;
 
  /**
   * The value represents the selected value
   */
  @Input()
  public get value(): Item | undefined {
    return this.storage.selected;
  }
 
  public set value(value: Item | undefined) {
    this.storage.selected = value;
  }
 
  @Input()
  public override get items(): readonly Item[] {
    return super.items;
  }
 
  public override set items(items: readonly Item[]) {
    super.items = items;
  }
 
  /** @ignore */
  public get _listboxId(): string {
    return this._widgetKeys.baseKey + '-lb';
  }
 
  /** @ignore */
  public get _ariaControls(): string | undefined {
    const idList = [
      this._impl_drawerOpen ? this._listboxId : '',
      this.controlledId,
    ]
      .join(' ')
      .trim();
 
    return idList ? idList : undefined;
  }
 
  public readonly _widgetKeys: WidgetKeySet = createWidgetKeySet(
    'gc-wizard-stepper-horizontal',
  );
 
  public _hasFocus = false;
 
  /**
   * @ignore
   */
  public _processItemText(text: string) {
    return textToLine(text, 32, '<br>');
  }
 
  public getAnker(): ElementRef<HTMLElement> {
    return this.button;
  }
 
  public getScrollTarget(): ElementRef<HTMLElement> | undefined {
    return this.containerElement;
  }
 
  public _isSelected(item: IndexedItem<Item>): boolean {
    return item.value === this.value;
  }
 
  public _isSelectable(key: Key): boolean {
    return this.selectableItems.some(i => i.key === key);
  }
 
  public _getAriaMessage(): string {
    const itemIndex = this.items.findIndex(i => i.key === this.value?.key);
    return (
      'Arbeitsschritt ' +
      (itemIndex !== -1 ? itemIndex + 1 : 1).toString() +
      ' von ' +
      this.items.length.toString() +
      '.'
    );
  }
 
  public _onSelect(event: SelectionEvent): void {
    const item = this.storage.indexItems.find(i => i.key === event.key);
    if (item && !this.disabledItems.has(item.key)) {
      this._impl_onSelect(item.key);
    }
  }
 
  /** @ignore */
  public _impl_onSelect(key: Key): void {
    if (!this._isDisabled(key)) {
      const value = this.storage.getValueByKey(key);
      if (value != undefined) {
        this._impl_handleChange(value);
        this._impl_close(true);
      }
    }
  }
 
  /** @ignore */
  public _impl_handleChange(value: Item): void {
    this.value = value;
    this.valueChange.emit(value);
  }
 
  /** @ignore */
  protected _impl_onOpen(focusItem: KeyFocusTarget): KeyFocusTarget {
    // always open selected value if set
    if (this.value != undefined) {
      const key = this.storage.getItemByValue(this.value)?.key;
      if (key != undefined) {
        focusItem = key;
      }
    }
    return focusItem;
  }
}