2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MUI TextField type='number'のスクロールイベントを止める

Last updated at Posted at 2023-02-10

概要

<TextField type='number' />を使っているとスクロールに従って数値が上下します。
このスクロールで勝手に値が増減しても困るので、止める方法を残します。

解決策

スクロールで増減するイベントはフォーカスなので、フォーカスで止めます。

import { BaseSyntheticEvent } from 'react'
import { TextField } from '@mui/material'

<TextField type='number' onFocus={(e: BaseSyntheticEvent) => e.target.blur()} />

blurイベントは、フォーカスが外れる時に起きるイベントで、フォーカス時に生じる
動作をフォーカスが外れた状態にすることで打ち消しています。

詳しくは以下の記事が参考になります。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?