Repository navigation
Void nodes, saving complex data structures #5180
Replies: 2 comments
|
After a lot of trial and error I figured out I can use Transforms to change Slate's data within a void, so I've got a component like this: This "works", but only when I first click on the div containing the input, which makes for terrible UX. Any suggestions on getting around this? |
|
The import { Transforms } from 'slate';
import { ReactEditor } from 'slate-react';
function AttributeInput({ editor, element, attributes, children }) {
return <div {...attributes} contentEditable={false}>
{children}
<input value={element.attributes?.value ?? ''} onChange={event => {
const path = ReactEditor.findPath(editor, element);
Transforms.setNodes(editor, {
attributes: { ...element.attributes, value: event.target.value },
}, { at: path, voids: true });
}}/>
</div>;
}The input reads its value from the Slate node, and the transform saves the new value on that same node. Spreading the existing I reproduced the selection dependence with Slate 0.133.7: the original ID-based |
Uh oh!
There was an error while loading. Please reload this page.
I was looking at the examples and stumbled upon the Void nodes example.
I thought I'd use something along these lines for:
However upon further inspection it doesn't look like any of the data from either the input or the select is saved in the editor.
Are there any examples on how something like this would be implemented? How do I save data besides
textto the current node?All reactions