Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
scrollTo(option) {
if (!document || !option) {
return;
}
let publicAPI = this.get('publicAPI');
let optionsList = document.getElementById(`ember-power-select-options-${publicAPI.uniqueId}`);
if (!optionsList) {
return;
}
let index = indexOfOption(publicAPI.results, option);
if (index === -1) {
return;
}
// Update the scroll index
this.updateState({ scrollIndex: index });
}
}
scrollTo(option, select) {
let optionsList = document.getElementById(`ember-power-select-options-${this.publicAPI.uniqueId}`);
if (!optionsList) {
return;
}
optionsList = optionsList.parentNode;
let index = indexOfOption(select.results, option);
if (index === -1) {
return;
}
let optionElement = optionsList.querySelector(`[data-option-index="${index}"]`);
if (!optionElement) {
return;
}
let optionTopScroll = optionElement.offsetTop;
let optionBottomScroll = optionTopScroll + optionElement.offsetHeight;
if (optionBottomScroll > optionsList.offsetHeight + optionsList.scrollTop) {
optionsList.scrollTop = optionBottomScroll - optionsList.offsetHeight;
} else if (optionTopScroll < optionsList.scrollTop) {
optionsList.scrollTop = optionTopScroll;
function advanceSelectableOption(options, currentOption, step) {
let resultsLength = countOptions(options);
let startIndex = Math.min(Math.max(indexOfOption(options, currentOption) + step, 0), resultsLength - 1);
let { disabled, option } = optionAtIndex(options, startIndex);
while (option && disabled) {
let next = optionAtIndex(options, startIndex += step);
disabled = next.disabled;
option = next.option;
}
return option;
}