[Slate-React] Inline placeholder is treated as part of editor content
See original GitHub issueWhen rendering an inline placeholder, it’s treated as part of the document and the cursor always appears after the placeholder (which doesn’t feel natural). My thought was maybe this has something to do with rendering and Slate.js measurements including the placeholder for cursor positioning.
function renderPlaceholder(props) {
const { document } = props.editor.value
if (document.text !== '' || document.nodes.size !== 1) return false
return (
<span
contentEditable={false}
styles={{ pointerEvents: 'none', userSelect: 'none' }}
>
{editor.props.placeholder}
</span>
)
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Slate js - How to render placeholders per line - jkrsp.com
In this tutorial I'll show you how to do this using Slate.js decorators. Setting up. If you haven't yet, [create a new react...
Read more >Migrating - Slate
Migrating from earlier versions of Slate to the 0.50.x versions is not a simple task. The entire framework was re-considered from the ground...
Read more >Text selection in React Slate no longer marked when focus ...
Slate doesn't hold the selection when you focus out of the editor due to a dropdown being opened. Now with buttons it is...
Read more >react-inline-edition - npm Package Health Analysis - Snyk
An inline, customizable and editable text component built in React. For more information about how to use this package see README.
Read more >Adding A Commenting System To A WYSIWYG Editor
Add a new mark to Slate document structure with the ID so the user sees that text highlighted. Add the new comment thread...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think perhaps we can do tricks in onSelect to move cursor back if there is placeholder but no content exists?
I will have a look at draft-js to see how they work: Update: draft-js let the editor as “position:relative”, then placeholder as “position:absolute”
But I think, if value is empty, then we can render an empty div with “position:relative”, then wrap the placeholder in that div
Ok, so did a bunch of digging. The cursor jump is caused by https://stackoverflow.com/questions/27786048/why-is-my-contenteditable-cursor-jumping-to-the-end-in-chrome - when placed next to the
contentEditable=false
and having no space, it’ll continue encountering the jump.One workaround would be to move the placeholder out of the
Content
- is there a reason it’s inside aNode
today?Edit: I see the jumping is probably why you put the placeholder before the node children instead of after too.