2024년 2월 29일 목요일

HTML Input Number type disable scroll

const MyNumberInput = () => {
  const numberInputOnWheelPreventChange = (e) => {
    // Prevent the input value change
    e.target.blur()

    // Prevent the page/container scrolling
    e.stopPropagation()

    // Refocus immediately, on the next tick (after the current     
    function is done)
      setTimeout(() => {
        e.target.focus()
    }, 0)
}

  return <input type="number" onWheel={numberInputOnWheelPreventChange}/>
}       

댓글 없음: