1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-23 15:32:59 +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,16 +63,11 @@ const VideoElement = ({ attributes, children, element }) => {
}} }}
/> />
</div> </div>
<input <UrlInput
value={url} url={url}
onClick={e => e.stopPropagation()} onChange={val => {
style={{
marginTop: '5px',
boxSizing: 'border-box',
}}
onChange={e => {
const path = ReactEditor.findPath(editor, element) const path = ReactEditor.findPath(editor, element)
Transforms.setNodes(editor, { url: e.target.value }, { at: path }) Transforms.setNodes(editor, { url: val }, { at: path })
}} }}
/> />
</div> </div>
@@ -81,6 +76,25 @@ const VideoElement = ({ attributes, children, element }) => {
) )
} }
const UrlInput = ({ url, onChange }) => {
const [value, setValue] = React.useState(url)
return (
<input
value={value}
onClick={e => e.stopPropagation()}
style={{
marginTop: '5px',
boxSizing: 'border-box',
}}
onChange={e => {
const newUrl = e.target.value
setValue(newUrl)
onChange(newUrl)
}}
/>
)
}
const initialValue = [ const initialValue = [
{ {
children: [ children: [