diff --git a/src/bubble-input.css b/src/bubble-input.css index 4722606..eaf0e84 100644 --- a/src/bubble-input.css +++ b/src/bubble-input.css @@ -1,6 +1,8 @@ .bubble.input { transition: opacity 0.4s ease-in-out; opacity: 1; + border: none; + outline: none; } .bubble.input.submitted { @@ -12,8 +14,6 @@ } .bubble.input > div { - border: none; - outline: none; background-color: #eee; font-size: 32px; min-width: 30px; diff --git a/src/bubble-input.jsx b/src/bubble-input.jsx index 892ab4b..9346d2f 100644 --- a/src/bubble-input.jsx +++ b/src/bubble-input.jsx @@ -1,31 +1,22 @@ import React, { useCallback, useState, useRef, useEffect } from 'react' import './bubble-input.css' -import ContentEditable from './content-editable' const BubbleInput = ({ onChange, onSubmit, value }) => { const refEditable = useRef() const [submitted, setSubmitted] = useState(false) - const handleChange = useCallback( - e => { - onChange && onChange(e.target.value) - }, - [onChange] - ) - const handleKeyDown = useCallback( - e => { - if (e.keyCode === 13) { - onSubmit && onSubmit() - e.preventDefault() - setSubmitted(true) - setTimeout(() => { - window.document.querySelector('.bubble.input > div').focus() - setSubmitted(false) - }, 10) - } - }, - [onSubmit] - ) + const handleKeyDown = e => { + if (e.key === 'Enter') { + onSubmit && onSubmit() + e.preventDefault() + setSubmitted(true) + setTimeout(() => { + refEditable.current.focus() + refEditable.current.innerText = '' + setSubmitted(false) + }, 10) + } + } const handleBlur = useCallback(() => { const { current: elDiv } = refEditable if (elDiv) { @@ -33,22 +24,20 @@ const BubbleInput = ({ onChange, onSubmit, value }) => { } }, [refEditable]) - useEffect(() => handleBlur(), [handleBlur]) + useEffect(handleBlur, [handleBlur]) return (