mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-30 02:19:52 +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:
committed by
Ian Storm Taylor
parent
fb728f4754
commit
1c29165661
@@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user