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

100% Statements 32/32
100% Branches 13/13
100% Functions 4/4
100% Lines 32/32

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 331x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 515x 1x 1x 1x 99x 99x 163x 163x 159x 159x 157x 99x 99x 99x 99x 1x 1x 53x 53x 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();
  }
}