question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change void nodes to pass the spacer as `props.children`

See original GitHub issue

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 has contenteditable="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 the props.attributes, which would ensure that the top-level element of the void node remains ineditable.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ianstormtaylorcommented, May 10, 2019

@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 props.children instead of the real content. Which is actually kind of cool, and unlocks some potentially advanced use cases I think.

And then the isVoid() query is mainly not a rendering construct, but a behavioral construct, to ensure that editing works as expected with void nodes (namely that their content is treated as atomic/un-editable).

1reaction
bengotowcommented, Nov 28, 2018

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 isVoid: true must now be specified in the schema and not on Block objects directly. The void node I was debugging was actually behaving as non-void and had a single child text node. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass props to {this.props.children} - Stack Overflow
Cloning children with new props. You can use React.Children to iterate over the children, and then clone each element with new props (shallow...
Read more >
Config · Native Navigation
children: node. If children are passed into the component, the Config 's render method will return the result of React.Children.only(this.props.children) .
Read more >
How to pass data to a React component's props.children
In the case of a single child, this can be accomplished by cloning it and adding a className prop with the value top...
Read more >
v-data-table API - Vuetify
Changes which item property should be used for grouping items. Currently only supports a ... Pass props to the default header. See v-data-table-header...
Read more >
LinearLayout | Android Developers
android:animateLayoutChanges, Defines whether changes in layout (caused by ... Prevents the specified child to be laid out during the next layout pass. void...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found