diff --git a/src/components/write/TagInput.tsx b/src/components/write/TagInput.tsx index 15450e5a..7739aa77 100644 --- a/src/components/write/TagInput.tsx +++ b/src/components/write/TagInput.tsx @@ -5,6 +5,7 @@ import palette from '../../lib/styles/palette'; import transitions from '../../lib/styles/transitions'; import { mediaQuery } from '../../lib/styles/media'; import { useTransition, animated } from 'react-spring'; +import OutsideClickHandler from 'react-outside-click-handler'; export interface TagInputProps { ref?: React.RefObject; @@ -24,7 +25,6 @@ const TagInput: React.FC = ({ onChange, tags: initialTags }) => { const [value, setValue] = useState(''); const [focus, setFocus] = useState(false); const ignore = useRef(false); - const editableDiv = useRef(null); useEffect(() => { if (tags.length === 0) return; @@ -39,13 +39,10 @@ const TagInput: React.FC = ({ onChange, tags: initialTags }) => { setValue(e.target.value); }; - useEffect(() => { - if (editableDiv.current) { - if (value === '') { - editableDiv.current.innerText = value; - } - } - }, [value]); + const onOutsideClick = () => { + if (value === '') return; + insertTag(value); + }; const insertTag = useCallback( (tag: string) => { @@ -96,23 +93,25 @@ const TagInput: React.FC = ({ onChange, tags: initialTags }) => { }; return ( - - {tags.map((tag) => ( - onRemove(tag)}> - {tag} - - ))} - setFocus(true)} - onBlur={() => setFocus(false)} - /> - - + + + {tags.map((tag) => ( + onRemove(tag)}> + {tag} + + ))} + setFocus(true)} + onBlur={() => setFocus(false)} + /> + + + ); };