diff --git a/packages/slate-react/src/components/leaf.js b/packages/slate-react/src/components/leaf.js index a85b5994b..17188d526 100644 --- a/packages/slate-react/src/components/leaf.js +++ b/packages/slate-react/src/components/leaf.js @@ -120,11 +120,15 @@ class Leaf extends React.Component { */ renderText() { - const { block, node, text, index, leaves } = this.props + const { block, node, parent, text, index, leaves } = this.props - // COMPAT: If the text is empty otherwise, it's because it's on the edge of - // an inline void node, so we render a zero-width space so that the - // selection can be inserted next to it still. + // COMPAT: Render text inside void nodes with a zero-width space. + // So the node can contain selection but the text is not visible. + if (parent.isVoid) return {'\u200B'} + + // COMPAT: If the text is empty, it's because it's on the edge of an inline + // void node, so we render a zero-width space so that the selection can be + // inserted next to it still. if (text == '') return {'\u200B'} // COMPAT: Browsers will collapse trailing new lines at the end of blocks, diff --git a/packages/slate-react/test/rendering/fixtures/custom-block-void.js b/packages/slate-react/test/rendering/fixtures/custom-block-void.js index a70ef97e9..a8cdd73f4 100644 --- a/packages/slate-react/test/rendering/fixtures/custom-block-void.js +++ b/packages/slate-react/test/rendering/fixtures/custom-block-void.js @@ -32,7 +32,9 @@ export const output = `
- + + +
diff --git a/packages/slate-react/test/rendering/fixtures/custom-inline-void.js b/packages/slate-react/test/rendering/fixtures/custom-inline-void.js index 5501dec2d..293a03dde 100644 --- a/packages/slate-react/test/rendering/fixtures/custom-inline-void.js +++ b/packages/slate-react/test/rendering/fixtures/custom-inline-void.js @@ -40,7 +40,9 @@ export const output = ` - + + +