packages/basic-component-mixins/src/SingleSelectionMixin.js
function selectIndex(element, index) {
  const count = element.items.length;

  const boundedIndex = (element.selectionWraps) ?
    // JavaScript mod doesn't handle negative numbers the way we want to wrap.
    // See http://stackoverflow.com/a/18618250/76472
    ((index % count) + count) % count :

    // Keep index within bounds of array.
    Math.max(Math.min(index, count - 1), 0);

  const previousIndex = element.selectedIndex;
  if (previousIndex !== boundedIndex) {
    element.selectedIndex = boundedIndex;
    return true;
  } else {
    return false;
  }
}
function selectIndex(element, index) {
  const count = element.items.length;

  const boundedIndex = (element.selectionWraps) ?
    // JavaScript mod doesn't handle negative numbers the way we want to wrap.
    // See http://stackoverflow.com/a/18618250/76472
    ((index % count) + count) % count :

    // Keep index within bounds of array.
    Math.max(Math.min(index, count - 1), 0);

  const previousIndex = element.selectedIndex;
  if (previousIndex !== boundedIndex) {
    element.selectedIndex = boundedIndex;
    return true;
  } else {
    return false;
  }
}
function selectIndex ( element , index ) { const count = element . items . length ; const boundedIndex = ( element . selectionWraps ) ? // JavaScript mod doesn't handle negative numbers the way we want to wrap. // See http://stackoverflow.com/a/18618250/76472 ( ( index % count ) + count ) % count : // Keep index within bounds of array. Math . max ( Math . min ( index , count - 1 ) , 0 ) ; const previousIndex = element . selectedIndex ; if ( previousIndex !== boundedIndex ) { element . selectedIndex = boundedIndex ; return true ; } else { return false ; } }
Ensure the given index is within bounds, and select it if it's not already selected.
Ensure the given index is within bounds and select it if it s not already selected .