Skip to content

Commit

Permalink
Merge pull request #479 from oneblink/ON-33356
Browse files Browse the repository at this point in the history
ON-33356 # reuse setTimeout in handling wheel event in number element
  • Loading branch information
mymattcarroll authored Jul 23, 2023
2 parents 4e5e51d + 6150583 commit 406a449
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/form-elements/FormElementNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,15 @@ function FormElementNumber({
[element, onChange],
)
const htmlInputElementRef = React.useRef<HTMLInputElement>(null)
const [trigger, setTrigger] = React.useState<boolean>(false)

//this onWheel callback prevents numbers changing while scrolling
const handleWheel = React.useCallback(() => {
htmlInputElementRef.current?.blur()
setTrigger((trigger) => !trigger)
setTimeout(() => {
htmlInputElementRef.current?.focus()
})
}, [])

React.useEffect(() => {
htmlInputElementRef.current?.focus({ preventScroll: true })
}, [trigger])

return (
<div className="cypress-number-element">
<FormElementLabelContainer
Expand Down

0 comments on commit 406a449

Please sign in to comment.