Skip to content
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

[Bug]: Text selection doesn't work in React node views #4036

Open
1 of 2 tasks
holdenmatt opened this issue May 10, 2023 · 3 comments
Open
1 of 2 tasks

[Bug]: Text selection doesn't work in React node views #4036

holdenmatt opened this issue May 10, 2023 · 3 comments
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Triage: Open A new issue or pullrequest that requires triage (added by default) Type: Bug The issue or pullrequest is related to a bug

Comments

@holdenmatt
Copy link

holdenmatt commented May 10, 2023

Which packages did you experience the bug in?

core, react

What Tiptap version are you using?

2.0.3

What’s the bug you are facing?

I'm rendering a table in a React node view, and would like to enable text in table cells to be selectable by users (i.e. user-select: auto), e.g. so they can copy/paste text to their clipboards.

It seems text cannot be selected by default in any React node view (see CodeSandbox for a minimal repro).

I suspect this is because a draggable="true" HTML attr is being added to a node when you start trying to select text, even though I have draggable: false on my node spec (seems odd - probably added by Prosemirror?).

If I set selectable: false on the node, it works (but this isn't desirable - I want the node to be selectable).

Text selection also works (but node selection doesn't) if I override stopEvent to stop all events:

stopEvent(e) {
  return true;
}

How can I enable text selection, without blocking node selection?

What browser are you using?

Chrome

Code example

https://codesandbox.io/s/tiptap-react-text-selection-bug-lvhk0e

What did you expect to happen?

I would expect text can be selected in interactive Node views (at least if the node isn't draggable). This seems like the most natural default (matching user-select: auto in the browser). A dev could set user-select: none if this isn't desired.

Or at least, there would be some workaround to enable text selection without disabling node selection completely.

Anything to add? (optional)

This part of stopEvent looks possibly related:

// ProseMirror tries to drag selectable nodes
// even if `draggable` is set to `false`
// this fix prevents that
if (!isDraggable && isSelectable && isDragEvent) {
event.preventDefault()
}

Did you update your dependencies?

  • Yes, I’ve updated my dependencies to use the latest version of all packages.

Are you sponsoring us?

  • Yes, I’m a sponsor. 💖
@holdenmatt holdenmatt added Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Triage: Open A new issue or pullrequest that requires triage (added by default) Type: Bug The issue or pullrequest is related to a bug labels May 10, 2023
@holdenmatt
Copy link
Author

Another possible clue.

  1. If a different node is selected, then you mousedown in a React node and drag, text is selectable (great!)
  2. However, if you click/mouseup to select the React node first, then text can't be selected.

I see draggable="true" being added in case 2 but not case 1:

image

@Nantris
Copy link
Contributor

Nantris commented May 17, 2023

Possibly related #2534.

@jsjoeio
Copy link

jsjoeio commented Jun 26, 2023

Unsure if related but I believe Beehiiv is using tiptap under the hood and there is a similar bug in their editor. When I select text, I cannot see that is selected. Digging into the CSS though, I see ::selection is being set to transparent:

image

I can overwrite the CSS but it's buggy

Screen.Recording.2023-06-26.at.4.12.24.PM.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. Triage: Open A new issue or pullrequest that requires triage (added by default) Type: Bug The issue or pullrequest is related to a bug
Projects
Status: Triage open
Development

No branches or pull requests

5 participants