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:
committed by
Ian Storm Taylor
parent
fb728f4754
commit
1c29165661
@@ -13,8 +13,7 @@ class Video extends React.Component {
|
|||||||
* @param {Event} e
|
* @param {Event} e
|
||||||
*/
|
*/
|
||||||
|
|
||||||
onChange = e => {
|
onChange = video => {
|
||||||
const video = e.target.value
|
|
||||||
const { node, editor } = this.props
|
const { node, editor } = this.props
|
||||||
editor.setNodeByKey(node.key, { data: { video } })
|
editor.setNodeByKey(node.key, { data: { video } })
|
||||||
}
|
}
|
||||||
@@ -108,8 +107,8 @@ class Video extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<input
|
<VideoUrlInput
|
||||||
value={video}
|
defaultValue={video}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onClick={this.onClick}
|
onClick={this.onClick}
|
||||||
style={style}
|
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.
|
* Export.
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user