nice-select2
nice-select2 copied to clipboard
Use arrow keys to navigate up and down when overflow-y is scrollable
So, the _onKeyPressed function selects the next element, but if there is overflow-y scroll applied to the ul list, it doesn't move the position with keycode = 38 and keycode = 40. User needs to use mouse to acually scroll thru list.
This is something that would be very nice to have :)
Many thanks!
Ivana
const niceSelect = new NiceSelect2(select, {});
// When niceSelect.dropdown gets the class open. find the li with the class .focus and scrollIntoView
niceSelect.dropdown.addEventListener('transitionend', () => {
if (niceSelect.dropdown.classList.contains('open')) {
const focus = niceSelect.dropdown.querySelector('.focus');
if (focus) {
focus.scrollIntoView({ block: 'nearest' });
}
}
});
Thank you! Works!
fixed