add input click away blur

This commit is contained in:
Qing
2022-09-21 21:56:51 +08:00
parent b1cebb614a
commit d8ed4d2a58
3 changed files with 27 additions and 5 deletions

View File

@@ -1,4 +1,5 @@
import React from 'react'
import React, { useRef } from 'react'
import { useClickAway } from 'react-use'
import NumberInput from '../shared/NumberInput'
import SettingBlock from './SettingBlock'
@@ -27,6 +28,15 @@ function NumberInputSetting(props: NumberInputSettingProps) {
disable,
} = props
const ref = useRef(null)
useClickAway<MouseEvent>(ref, () => {
if (ref?.current) {
const input = ref.current as HTMLInputElement
input.blur()
}
})
return (
<SettingBlock
className="sub-setting-block"
@@ -47,6 +57,7 @@ function NumberInputSetting(props: NumberInputSettingProps) {
value={value}
disabled={disable}
onValue={onValue}
ref={ref}
/>
{suffix && <span>{suffix}</span>}
</div>