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

Not possible to triple click when checklist is the next block #4528

Open
churichard opened this issue Sep 15, 2021 · 2 comments
Open

Not possible to triple click when checklist is the next block #4528

churichard opened this issue Sep 15, 2021 · 2 comments
Labels

Comments

@churichard
Copy link

churichard commented Sep 15, 2021

Description
When a checklist item is the block on the next line, it's not possible to triple click to select text. The selection immediately disappears.

It's still possible to select text by clicking and dragging, or by triple clicking to the right of the block. You just can't do it in the middle of the text.

Recording
https://user-images.githubusercontent.com/4218237/133506943-58814de9-40d5-4a25-b618-475f43e687e5.mp4

I'm triple clicking and most of the time, the selection flashes and then disappears.

Sandbox
https://www.slatejs.org/examples/check-lists

Steps
To reproduce the behavior:

  1. Go to https://www.slatejs.org/examples/check-lists
  2. Try to triple click the first block and observe that the selection does not stay highlighted

Expectation
You should be able to triple click and have the selection be highlighted

Environment

  • Slate Version: 0.66.1
  • Operating System: Windows
  • Browser: Chrome

Additional context
For a reference implementation that works better than Slate's implementation, check out the way Plate does it: https://github.com/udecode/plate/blob/89232685952dbfa1dca6f8240d9021e005f15c42/packages/elements/list-ui/src/TodoListElement/TodoListElement.tsx

I'm not sure if there is a bug in Slate that makes it so Slate's implementation doesn't work, but Plate works around it by adjusting how checklists are rendered.

@churichard churichard added the bug label Sep 15, 2021
@dylans
Copy link
Collaborator

dylans commented Sep 16, 2021

This sounds like a consequence of the changes in #4455 and #4498

@jamfromouterspace
Copy link

jamfromouterspace commented Sep 29, 2021

Since this doesn't happen on bullet lists, I fixed it by rendering my checklists like this:

  switch (element.type) {
    case "check-list-item":
      return (
        <li
          {...attributes}
          className={css`
            list-style: none;
          `}
        >
          <input
            type="checkbox"
            contentEditable={false}
            checked={element.checked}
            onChange={(event) => {
              const path = ReactEditor.findPath(editor, element)
              const newProperties = {
                checked: event.target.checked,
              }
              Transforms.setNodes(editor, newProperties, { at: path })
            }}
          />
          {children}
        </li>
      )
    case "bulleted-list":
      return <li {...attributes}>{children}</li>
   ...

Make sure contentEditable is false in the input.

Edit: Okay, it looks like this still works when you use a div instead of an li. Maybe something about nesting another div inside (as is the case in the example code and even in Plate) throws off the triple-click detection mentioned in the PRs above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants