1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-24 07:52:50 +02:00

use state to avoid cursor jumping in controlled input (#3552)

Co-authored-by: dal <test@x.com>
This commit is contained in:
Entkenntnis
2020-03-25 02:16:32 +01:00
committed by GitHub
parent 5da89b8656
commit 1d7ab97429

View File

@@ -63,21 +63,35 @@ const VideoElement = ({ attributes, children, element }) => {
}} }}
/> />
</div> </div>
<UrlInput
url={url}
onChange={val => {
const path = ReactEditor.findPath(editor, element)
Transforms.setNodes(editor, { url: val }, { at: path })
}}
/>
</div>
{children}
</div>
)
}
const UrlInput = ({ url, onChange }) => {
const [value, setValue] = React.useState(url)
return (
<input <input
value={url} value={value}
onClick={e => e.stopPropagation()} onClick={e => e.stopPropagation()}
style={{ style={{
marginTop: '5px', marginTop: '5px',
boxSizing: 'border-box', boxSizing: 'border-box',
}} }}
onChange={e => { onChange={e => {
const path = ReactEditor.findPath(editor, element) const newUrl = e.target.value
Transforms.setNodes(editor, { url: e.target.value }, { at: path }) setValue(newUrl)
onChange(newUrl)
}} }}
/> />
</div>
{children}
</div>
) )
} }