Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (
!hasClass(
items[currentIndex] as HTMLElement,
wheelDisabledItemClassName
)
) {
break
}
currentIndex--
}
if (currentIndex < 0) {
currentIndex = cacheIndex
while (currentIndex <= items.length - 1) {
if (
!hasClass(
items[currentIndex] as HTMLElement,
wheelDisabledItemClassName
)
) {
break
}
currentIndex++
}
}
// keep it unchange when all the items are disabled
if (currentIndex === items.length) {
currentIndex = cacheIndex
}
// when all the items are disabled, this.selectedIndex should always be -1
return {
private findNearestValidWheel(y: number) {
y = y > 0 ? 0 : y < this.scroll.maxScrollY ? this.scroll.maxScrollY : y
let currentIndex = Math.abs(Math.round(-y / this.itemHeight))
const cacheIndex = currentIndex
const items = this.items
const wheelDisabledItemClassName = this.options
.wheelDisabledItemClass as string
// Impersonation web native select
// first, check whether there is a enable item whose index is smaller than currentIndex
// then, check whether there is a enable item whose index is bigger than currentIndex
// otherwise, there are all disabled items, just keep currentIndex unchange
while (currentIndex >= 0) {
if (
!hasClass(
items[currentIndex] as HTMLElement,
wheelDisabledItemClassName
)
) {
break
}
currentIndex--
}
if (currentIndex < 0) {
currentIndex = cacheIndex
while (currentIndex <= items.length - 1) {
if (
!hasClass(
items[currentIndex] as HTMLElement,
wheelDisabledItemClassName
private checkWheelAllDisabled() {
const wheelDisabledItemClassName = this.options
.wheelDisabledItemClass as string
const items = this.items
this.wheelItemsAllDisabled = true
for (let i = 0; i < items.length; i++) {
if (!hasClass(items[i] as HTMLElement, wheelDisabledItemClassName)) {
this.wheelItemsAllDisabled = false
break
}
}
}
}
(el: HTMLElement, pos: { top: number; left: number }) => {
if (!hasClass(el, this.options.wheelItemClass!)) {
return true
} else {
pos.top = this.findNearestValidWheel(pos.top).y
}
}
)