Skip to content

The open alternative to Salesforce, designed for AI.

581 B
Raw Blame
import { type SelectorElementLike } from '@/polyfills/selectors/types/SelectorElementLike';
import { collectOptionsOfSelect } from '@/polyfills/selectors/utils/collectOptionsOfSelect';

export const applySelectedOptionIndexes = ({
  element,
  selectedOptionIndexes,
}: {
  element: SelectorElementLike;
  selectedOptionIndexes: number[];
}): void => {
  const selectedOptionIndexSet = new Set(selectedOptionIndexes);

  for (const [optionIndex, option] of collectOptionsOfSelect(
    element,
  ).entries()) {
    option.selected = selectedOptionIndexSet.has(optionIndex);
  }
};