1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 10:29:48 +02:00

fix cursor jumping to end in embeds example (#3014)

* fix cursor jumping to end in embeds example

* prettier

* prettier again
This commit is contained in:
Entkenntnis
2019-09-21 19:44:57 +02:00
committed by Ian Storm Taylor
parent fb728f4754
commit 1c29165661

View File

@@ -13,8 +13,7 @@ class Video extends React.Component {
* @param {Event} e
*/
onChange = e => {
const video = e.target.value
onChange = video => {
const { node, editor } = this.props
editor.setNodeByKey(node.key, { data: { video } })
}
@@ -108,8 +107,8 @@ class Video extends React.Component {
}
return (
<input
value={video}
<VideoUrlInput
defaultValue={video}
onChange={this.onChange}
onClick={this.onClick}
style={style}
@@ -118,6 +117,33 @@ class Video extends React.Component {
}
}
/**
* The video URL input as controlled input to avoid loosing cursor position.
*
* @type {Component}
*/
const VideoUrlInput = props => {
const [val, setVal] = React.useState(props.defaultValue)
const onChange = React.useCallback(
e => {
setVal(e.target.value)
props.onChange(e.target.value)
},
[props.onChange]
)
return (
<input
value={val}
onChange={onChange}
onClick={props.onClick}
style={props.style}
/>
)
}
/**
* Export.
*/