-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
change void nodes to pass the spacer as props.children
#1884
Comments
Hey folks—it seems like this issue has been merged and can probably be closed! |
@bengotow I don't think it has yet. |
Hey thanks for the reply! It looks like my problem was that I was upgrading from an older version of Slate to the latest version and didn't realize that |
Experimented a little bit with this, see this commit. It works wonderfully like this but I don't see any ways to decrease the amount of properties user has to add/spread because selection works properly only with the following structure: // in renderBlock
return (
<div {...props.voidAttrs}> {/* data-slate-void="true" data-key="1871" */}
{props.spacer}
<div contentEditable={false}> {/* has to be here like everything else */}
<img
{...attributes} {/* data-slate-object="block" data-key="1871" */}
src={src}
className={css`
display: block;
max-width: 100%;
max-height: 20em;
box-shadow: ${isFocused ? '0 0 0 2px blue;' : 'none'};
`}
/>
</div>
</div>
) If you remove any elements, selection is messed up. |
@adjourn nice! I think we can update the selection logic around return (
<div {...props.attributes}> {/* data-slate-object="block" data-slate-void="true" data-key="1871" */}
{props.children}
<div contentEditable={false}> {/* has to be here */}
<img
src={src}
className={css`
display: block;
max-width: 100%;
max-height: 20em;
box-shadow: ${isFocused ? '0 0 0 2px blue;' : 'none'};
`}
/>
</div>
</div>
) The even more ideal would be that people didn't have to add the extra (Actually, we might even be able to remove the |
@adjourn specifically, in here: slate/packages/slate-react/src/plugins/react/queries.js Lines 325 to 341 in 376015d
In the |
I'm not super adept in Slate selection code but I see where you're going with this. What would that mean to void? You could add spacer (if provided) and I'll try to wrap my head around selection logic some time soon and even if I don't contribute to this issue, it can't hurt in the long run. |
@adjourn you're right. It would technically mean that at render-time the only difference between voids and non-voids is that the "spacer" content is added to And then the |
Fixed by #3093. |
Do you want to request a feature or report a bug?
Improvement.
What's the current behavior?
Right now when rendering a void node, Slate wraps the node in a
<div>
or<span>
so that it can put a "spacer" next to it. This is needed to capture the browser's native selection behavior, since the void node hascontenteditable="false"
.However, this also means that you can't control the top-level element that is rendered in the editor. Which is unfortunate in many use cases. For example one where you want to style adjacent void nodes. You can't just use the
& + &
CSS selector, since they aren't actually adjacent in the DOM.What's the expected behavior?
I think...
We could solve this by passing the spacer as
props.children
, and requiring that users render it in their void node. (This is even more consistent with how we render non-void nodes actually.)Similarly, we'd add the
contenteditable="false"
to theprops.attributes
, which would ensure that the top-level element of the void node remains ineditable.The text was updated successfully, but these errors were encountered: