Skip to content

Commit

Permalink
fix(fields): add debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Sep 26, 2024
1 parent 8e864da commit 79b19fb
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/fields/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getSelectedOptionValueFromSelectedRsuiteDataItemValue } from '@utils/getSelectedOptionValueFromSelectedRsuiteDataItemValue'
import classnames from 'classnames'
import { debounce } from 'lodash'
import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { SelectPicker as RsuiteSelectPicker, type SelectPickerProps as RsuiteSelectPickerProps } from 'rsuite'

Expand Down Expand Up @@ -137,28 +138,26 @@ export function Select<OptionValue extends OptionValueType = string>({
() =>
originalProps.virtualized
? {
onItemsRendered: () => {
setTimeout(() => {
if (!boxRef.current) {
return
}

const divs = boxRef.current.querySelectorAll(`#${originalProps.name}-listbox div`)
const targetDiv = divs[2]

/**
* Reset the 'pointer-events' style
* @see:
* https://github.com/MTES-MCT/monitorfish/issues/3211
* https://github.com/bvaughn/react-window/issues/128
*/
if (targetDiv) {
requestAnimationFrame(() => {
;(targetDiv as HTMLDivElement).style.pointerEvents = 'auto'
})
}
}, 300)
}
onItemsRendered: debounce(() => {
if (!boxRef.current) {
return
}

const divs = boxRef.current.querySelectorAll(`#${originalProps.name}-listbox div`)
const targetDiv = divs[2]

/**
* Reset the 'pointer-events' style
* @see:
* https://github.com/MTES-MCT/monitorfish/issues/3211
* https://github.com/bvaughn/react-window/issues/128
*/
if (targetDiv) {
requestAnimationFrame(() => {
;(targetDiv as HTMLDivElement).style.pointerEvents = 'auto'
})
}
}, 300)
}
: {},
[originalProps.virtualized, originalProps.name]
Expand Down

0 comments on commit 79b19fb

Please sign in to comment.