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.

[Slate-React] Inline placeholder is treated as part of editor content

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
zhujinxuancommented, Apr 30, 2018

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

1reaction
blakeembreycommented, Oct 31, 2017

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 a Node today?

Edit: I see the jumping is probably why you put the placeholder before the node children instead of after too.

Read more comments on GitHub >

github_iconTop 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 >

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