diff --git a/lama_cleaner/app/src/components/Header/PromptInput.tsx b/lama_cleaner/app/src/components/Header/PromptInput.tsx index 7d0d3a5..bd667bc 100644 --- a/lama_cleaner/app/src/components/Header/PromptInput.tsx +++ b/lama_cleaner/app/src/components/Header/PromptInput.tsx @@ -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) => { evt.preventDefault() @@ -23,9 +25,17 @@ const PromptInput = () => { } } + useClickAway(ref, () => { + if (ref?.current) { + const input = ref.current as HTMLInputElement + input.blur() + } + }) + return (
(ref, () => { + if (ref?.current) { + const input = ref.current as HTMLInputElement + input.blur() + } + }) + return ( {suffix && {suffix}}
diff --git a/lama_cleaner/app/src/components/shared/Input.tsx b/lama_cleaner/app/src/components/shared/Input.tsx index 5646bff..421987a 100644 --- a/lama_cleaner/app/src/components/shared/Input.tsx +++ b/lama_cleaner/app/src/components/shared/Input.tsx @@ -1,11 +1,12 @@ -import React, { FocusEvent, InputHTMLAttributes } from 'react' +import React, { FocusEvent, InputHTMLAttributes, RefObject } from 'react' +import { useClickAway } from 'react-use' import { useRecoilState } from 'recoil' import { appState } from '../../store/Atoms' const TextInput = React.forwardRef< HTMLInputElement, InputHTMLAttributes ->((props: InputHTMLAttributes, forwardedRef) => { +>((props, ref) => { const { onFocus, onBlur, ...itemProps } = props const [_, setAppState] = useRecoilState(appState) @@ -26,7 +27,7 @@ const TextInput = React.forwardRef< return (