Scroll the first selected option into the view

This commit is contained in:
Sebastian Zoglowek 2025-11-26 19:14:25 +01:00
commit 6b30de46e6

View file

@ -521,6 +521,15 @@ class Choices {
}
this.passedElement.triggerEvent(EventType.showDropdown);
const activeElement = this.choiceList.element.querySelector<HTMLElement>(
getClassNamesSelector(this.config.classNames.selectedState),
);
if (activeElement !== null && !isScrolledIntoView(activeElement, this.choiceList.element)) {
// We use the native scrollIntoView function instead of choiceList.scrollToChildElement to avoid smooth scroll.
activeElement.scrollIntoView();
}
});
return this;