All files / packages/theme-selector/src/dropdown helpers.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 2/2
100% Lines 6/6

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                  195x 46x   149x   195x             34x 197x      
// SPDX-License-Identifier: MIT
/**
 * Dropdown helper functions
 */
 
/**
 * Sets the active state (is-active class and aria-checked) on a theme item element.
 */
export function setItemActiveState(item: Element, isActive: boolean): void {
  if (isActive) {
    item.classList.add('is-active');
  } else {
    item.classList.remove('is-active');
  }
  item.setAttribute('aria-checked', String(isActive));
}
 
/**
 * Sets tabindex attribute on all items in a collection.
 */
export function setTabindexBatch(items: HTMLElement[], value: string): void {
  for (const item of items) {
    item.setAttribute('tabindex', value);
  }
}