mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
fixed some bugs with the input event handler on the embeds example (#3516)
* fixed some bugs with the input event handler on the embeds example, got rid of the non functional 'is selected and is focused' conditions for showing the input. * fix linting error Co-authored-by: DamareYoh <34608378+DamareYoh@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useMemo } from 'react'
|
||||
import { Editor, createEditor } from 'slate'
|
||||
import { Transforms, createEditor } from 'slate'
|
||||
import {
|
||||
Slate,
|
||||
Editable,
|
||||
@@ -41,30 +41,10 @@ const Element = props => {
|
||||
|
||||
const VideoElement = ({ attributes, children, element }) => {
|
||||
const editor = useEditor()
|
||||
const selected = useSelected()
|
||||
const focused = useFocused()
|
||||
const { url } = element
|
||||
return (
|
||||
<div {...attributes}>
|
||||
<div
|
||||
contentEditable={false}
|
||||
style={{
|
||||
position: 'relative',
|
||||
boxShadow: selected && focused ? '0 0 0 3px #B4D5FF' : 'none',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
display: selected && focused ? 'none' : 'block',
|
||||
position: 'absolute',
|
||||
top: '0',
|
||||
left: '0',
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
cursor: 'cell',
|
||||
zIndex: 1,
|
||||
}}
|
||||
/>
|
||||
<div contentEditable={false}>
|
||||
<div
|
||||
style={{
|
||||
padding: '75% 0 0 0',
|
||||
@@ -83,7 +63,6 @@ const VideoElement = ({ attributes, children, element }) => {
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{selected && focused ? (
|
||||
<input
|
||||
value={url}
|
||||
onClick={e => e.stopPropagation()}
|
||||
@@ -91,12 +70,11 @@ const VideoElement = ({ attributes, children, element }) => {
|
||||
marginTop: '5px',
|
||||
boxSizing: 'border-box',
|
||||
}}
|
||||
onChange={value => {
|
||||
onChange={e => {
|
||||
const path = ReactEditor.findPath(editor, element)
|
||||
Transforms.setNodes(editor, { url: value }, { at: path })
|
||||
Transforms.setNodes(editor, { url: e.target.value }, { at: path })
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user