All files / lib/internal combobox-list.directive.ts

100% Statements 36/36
100% Branches 14/14
100% Functions 5/5
100% Lines 36/36

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 371x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 519x 1x 1x 1x 100x 100x 165x 165x 161x 161x 159x 100x 100x 100x 100x 1x 1x 54x 54x 1x 1x 2x 2x 1x  
import { ContentChildren, Directive, QueryList } from '@angular/core';
 
import { IndexedItem } from '../utils/internal-utils';
import { Item } from '../utils/util.types';
 
import { ComboBoxOptionDirective } from './combobox-option.directive';
 
@Directive({
  selector: '[data-gc-combobox-list]',
  standalone: false,
})
export class ComboBoxListDirective<T, I extends Item> {
  @ContentChildren(ComboBoxOptionDirective)
  public options!: QueryList<ComboBoxOptionDirective<T, I>>;
 
  scrollIntoView(value: IndexedItem<T | null, I>): void {
    const valId = value.key;
    const found = this.options.find((op: ComboBoxOptionDirective<T, I>) => {
      if (op.item === undefined) {
        return false;
      }
      const opId = op.item.key;
      return valId == opId;
    });
 
    found?.scrollIntoView();
  }
 
  scrollToFirst(): void {
    this.options.get(0)?.scrollIntoView();
  }
 
  scrollToLast(): void {
    this.options.get(this.options.length - 1)?.scrollIntoView();
  }
}