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, { FormEvent, useState } from 'react'
import React, { FormEvent, useRef, useState } from 'react'
import { useClickAway } from 'react-use'
import { useRecoilState } from 'recoil'
import emitter, { EVENT_PROMPT } from '../../event'
import { appState, propmtState } from '../../store/Atoms'
@@ -9,6 +10,7 @@ import TextInput from '../shared/Input'
const PromptInput = () => {
const [app, setAppState] = useRecoilState(appState)
const [prompt, setPrompt] = useRecoilState(propmtState)
const ref = useRef(null)
const handleOnInput = (evt: FormEvent<HTMLInputElement>) => {
evt.preventDefault()
@@ -23,9 +25,17 @@ const PromptInput = () => {
}
}
useClickAway<MouseEvent>(ref, () => {
if (ref?.current) {
const input = ref.current as HTMLInputElement
input.blur()
}
})
return (
<div className="prompt-wrapper">
<TextInput
ref={ref}
value={prompt}
onInput={handleOnInput}
placeholder="I want to repaint of..."