All files / lib/dynamic-form-input/dynamic-form-combobox dynamic-form-combobox.component.ts

100% Statements 10/10
83.33% Branches 5/6
100% Functions 5/5
100% Lines 9/9

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                  1x     5x 5x       5x   6x         6x 6x 6x 3x        
import { Component, OnInit } from '@angular/core';
import { DynamicFormCombobox, DynamicFormInputBase, DynamicFormValidationService } from '@dynamic-forms/core';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
 
@Component({
  selector: 'mat-dynamic-form-combobox',
  templateUrl: './dynamic-form-combobox.component.html',
})
export class MatDynamicFormComboboxComponent extends DynamicFormInputBase<DynamicFormCombobox> implements OnInit {
  filteredOptions: Observable<string[]>;
 
  constructor(protected override validationService: DynamicFormValidationService) {
    super(validationService);
  }
 
  ngOnInit(): void {
    this.filteredOptions = this.control.valueChanges.pipe(
      startWith(''),
      map(value => this.getFilteredOptions(value)),
    );
  }
 
  private getFilteredOptions(value: string): string[] {
    const options = this.input.options || [];
    const valueNormalized = value ? value.toUpperCase() : null;
    return valueNormalized
      ? options.filter(option => option.toUpperCase().includes(valueNormalized))
      : options;
  }
}