All files / filtered-search/values si-filtered-search-value.base.ts

100% Statements 16/16
80% Branches 4/5
100% Functions 3/3
100% Lines 16/16

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                              1x 113x 113x 113x 113x 113x   113x 113x 113x         113x     60x       4x       4x 4x         5x 3x        
/**
 * Copyright (c) Siemens 2016 - 2025
 * SPDX-License-Identifier: MIT
 */
import { Directive, ElementRef, input, model, output, signal, Signal } from '@angular/core';
import { TranslatableString } from '@siemens/element-translate-ng/translate';
 
import { CriterionDefinition, CriterionValue } from '../si-filtered-search.model';
 
@Directive({
  host: {
    '[class.invalid-criterion]': '!validValue()',
    'class': 'pill pill-interactive px-0 criterion-value-section'
  }
})
export abstract class SiFilteredSearchValueBase {
  readonly active = model.required<boolean>();
  readonly criterionValue = model.required<CriterionValue>();
  readonly definition = input.required<CriterionDefinition>();
  readonly disabled = input.required<boolean>();
  readonly searchLabel = input.required<TranslatableString>();
 
  readonly submitValue = output<{ freeText: string } | void>();
  readonly editValue = output();
  readonly backspaceOverflow = output();
 
  protected abstract readonly valueInput: Signal<ElementRef<HTMLInputElement> | undefined>;
  protected abstract readonly validValue: Signal<boolean>;
 
  readonly focusInOverlay = signal(false).asReadonly();
 
  focus(): void {
    this.valueInput()?.nativeElement.focus();
  }
 
  protected valueEnter(): void {
    if (
      !this.definition().multiSelect &&
      (this.criterionValue().value || this.criterionValue().dateValue)
    ) {
      this.active.set(false);
      this.submitValue.emit();
    }
  }
 
  protected valueBackspace(): void {
    if (!this.valueInput()!.nativeElement.value) {
      this.backspaceOverflow.emit();
    }
  }
}