Skip to content

[lexical-list] Bug Fix: Dragging a selection onto a check box no longer checks the item - #9429

Open
Vedthakar wants to merge 3 commits into
meta:mainfrom
Vedthakar:fix/4861-checklist-drag-release
Open

Vedthakar wants to merge 3 commits into
meta:mainfrom
Vedthakar:fix/4861-checklist-drag-release

Conversation

@Vedthakar

Copy link
Copy Markdown
Contributor

Description

This solves issue #4861: a check list item gets checked when you select its text by dragging and release the mouse over its check box.

Current behavior. A drag that starts in the item's text and ends over the check mark still produces a click on the <li>, the nearest common ancestor of the press and the release. handleCheckItemEvent decides from that click's coordinates only, which are the release point, so the item toggles.

The plugin already records what each press landed on (lastPress: 'checkMark', 'content' or 'none') for its focus handling, but it can't be used as it stands. The pointerup handler runs before the click and resets lastPress to 'none'. By the time the click arrives, every real mouse gesture looks like a press-less click.

What this changes.

  • The pointerup handler keeps the press of the gesture it ended (releasedPress) for the click that follows. It only does this for the primary button, since a right click has no click after it.
  • click and the touch pointerup path toggle only when that press wasn't on the item's content:
    • a press on the check mark still toggles;
    • 'none' (a click with no press behind it, such as one a screen reader synthesizes) still toggles;
    • a press on the content released over the check mark no longer toggles.
  • releasedPress is cleared by the click and by the next press, so it never carries over to a later gesture.
  • The focus handling and the touch dedup window are unchanged.

This doesn't overlap with open PR #9106, which edits a different part of checkList.ts (the Space handler).

Closes #4861

Test plan

New tests in packages/lexical-list/src/__tests__/unit/checkList.test.tsx, which already stubs the ::before width for jsdom. They dispatch full gestures: pointerdown/mousedown, pointerup/mouseup, click.

  • "does not toggle the item (a text selection dragged onto it)": a mouse press on the content, released over the check mark.
  • "does not toggle the item on touch either": the same with touch pointer events.
  • "does not carry over to a later check mark press": a drag like the one above, then a normal check mark click, toggles exactly once.
  • Controls:
    • a press and release on the check mark still toggles;
    • a click with no press (screen reader) still toggles;
    • after a right click on the content, the next click on the check mark still toggles.

The existing mobile tap and dedup tests in the file pass unchanged.

Before

On main with the tests applied and the source change reverted:

$ pnpm exec vitest run packages/lexical-list/src/__tests__/unit/checkList.test.tsx
  × does not toggle the item (a text selection dragged onto it)
  × does not toggle the item on touch either
  × does not carry over to a later check mark press
  Tests  3 failed | 9 passed (12)

After

On current main:

  • checkList.test.tsx: 12 passed (the 3 new behaviour tests fail on main). Chromium e2e: List.spec.mjs, which covers check lists, passes in full.
  • pnpm run test-unit: all 9,580 tests pass
  • tsc, pnpm run flow (0 errors), and eslint/prettier on the changed files: clean

Author: Ved Thakar (@Vedthakar)

🤖 Generated with Claude Code

@vercel

vercel Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Nov 16, 2026 11:57pm UTC
lexical-playground Ready Ready Preview Nov 16, 2026 11:57pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
lexical

npm i https://pkg.pr.new/lexical@9429

@lexical/a11y

npm i https://pkg.pr.new/@lexical/a11y@9429

@lexical/clipboard

npm i https://pkg.pr.new/@lexical/clipboard@9429

@lexical/code

npm i https://pkg.pr.new/@lexical/code@9429

@lexical/code-core

npm i https://pkg.pr.new/@lexical/code-core@9429

@lexical/code-prism

npm i https://pkg.pr.new/@lexical/code-prism@9429

@lexical/code-shiki

npm i https://pkg.pr.new/@lexical/code-shiki@9429

@lexical/compiler

npm i https://pkg.pr.new/@lexical/compiler@9429

@lexical/devtools-core

npm i https://pkg.pr.new/@lexical/devtools-core@9429

@lexical/dragon

npm i https://pkg.pr.new/@lexical/dragon@9429

@lexical/eslint-plugin

npm i https://pkg.pr.new/@lexical/eslint-plugin@9429

@lexical/extension

npm i https://pkg.pr.new/@lexical/extension@9429

@lexical/fast-check

npm i https://pkg.pr.new/@lexical/fast-check@9429

@lexical/file

npm i https://pkg.pr.new/@lexical/file@9429

@lexical/hashtag

npm i https://pkg.pr.new/@lexical/hashtag@9429

@lexical/headless

npm i https://pkg.pr.new/@lexical/headless@9429

@lexical/history

npm i https://pkg.pr.new/@lexical/history@9429

@lexical/html

npm i https://pkg.pr.new/@lexical/html@9429

@lexical/internal

npm i https://pkg.pr.new/@lexical/internal@9429

@lexical/link

npm i https://pkg.pr.new/@lexical/link@9429

@lexical/list

npm i https://pkg.pr.new/@lexical/list@9429

@lexical/mark

npm i https://pkg.pr.new/@lexical/mark@9429

@lexical/markdown

npm i https://pkg.pr.new/@lexical/markdown@9429

@lexical/mdast

npm i https://pkg.pr.new/@lexical/mdast@9429

@lexical/offset

npm i https://pkg.pr.new/@lexical/offset@9429

@lexical/overflow

npm i https://pkg.pr.new/@lexical/overflow@9429

@lexical/plain-text

npm i https://pkg.pr.new/@lexical/plain-text@9429

@lexical/react

npm i https://pkg.pr.new/@lexical/react@9429

@lexical/rich-text

npm i https://pkg.pr.new/@lexical/rich-text@9429

@lexical/selection

npm i https://pkg.pr.new/@lexical/selection@9429

@lexical/table

npm i https://pkg.pr.new/@lexical/table@9429

@lexical/tailwind

npm i https://pkg.pr.new/@lexical/tailwind@9429

@lexical/text

npm i https://pkg.pr.new/@lexical/text@9429

@lexical/utils

npm i https://pkg.pr.new/@lexical/utils@9429

@lexical/y

npm i https://pkg.pr.new/@lexical/y@9429

@lexical/yjs

npm i https://pkg.pr.new/@lexical/yjs@9429

commit: 0341ba9

vjeux added a commit to vjeux/lexical that referenced this pull request Nov 3, 2026
… toggles the item

## Description

On a touch screen, a finger that lands on a check list item's check mark and moves, for example to scroll through the list, toggles the item when it lifts. Only a tap should.

Touch pointers are captured by the element they went down on, so the `pointerup` of that swipe still reaches the item, and the touch `pointerup` path decides from the release point's x coordinate alone, which a vertical swipe keeps inside the check mark's hit area.

That path now remembers where each touch went down and ignores a release more than 10px from it along either axis, the same test as core's tap detection; `pointercancel` forgets the touch. A tap, a few pixels of jitter included, toggles as before, and a release with no recorded press is still treated as a tap. The `touchstart` handling is unchanged, so a swipe that starts on a check mark still doesn't scroll the page; this change only stops the toggle. It is separate from meta#9429, which stops a press on the item's text that is released over the check mark from toggling it.

## Test plan

### Before

The new tests on `main`:

```
$ pnpm exec vitest run --project unit packages/lexical-list/src/__tests__/unit/checkList.test.tsx
     × a touch that moves before lifting does not toggle the item
     ✓ a tap that moves a few pixels still toggles the item
AssertionError: expected true to be false // Object.is equality
      Tests  1 failed | 7 passed (8)
```

### After

```
$ pnpm exec vitest run --project unit packages/lexical-list
      Tests  170 passed (170)
$ pnpm exec vitest run --project unit
 Test Files  679 passed | 4 skipped (683)
      Tests  29169 passed | 373 expected fail | 136 skipped (29678)
```

`pnpm run tsc`, `pnpm run tsc-test`, `pnpm run flow`, `pnpm run check-changesets`, and ESLint and Prettier on the changed files pass. The tests dispatch the pointer events in jsdom; not run on a touch device or simulator.

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix — this looks good. The drag-from-label case is handled with a small, contained change, and the new tests fail on main and pass here. A few optional, non-blocking suggestions:

  1. A press that never finishes inside the editor can veto a later press-less click (packages/lexical-list/src/checkList.ts, lines 156-163 and 292-306). lastPress is only consumed by the root's pointerup/click listeners, so after a pointercancel (a touch scroll, or a native drag starting) or a selection dragged out of the editor and released outside it, lastPress stays 'content'; releasedPress likewise lingers after a primary release that no click follows. The next click with no press behind it — the case the description says should still toggle — is then skipped until the user presses somewhere in the editor again. Resetting both on pointercancel, and applying the content veto only to the click that directly follows the root's own pointerup, would close this. Each case is a short unit test next to the new ones, e.g. a touch pointerdown on the label, then pointercancel, then a click on the check mark should still toggle.

  2. Consider a real-browser test as well. The new tests run in jsdom with hand-built event sequences, so they cannot show that a browser actually delivers the click to the <li> at the release point. AGENTS.md (Testing Strategy) puts behaviour that depends on a real layout or selection engine in browser or e2e tests, and packages/lexical-playground/__tests__/e2e/List.spec.mjs already drives check lists with page.mouse: mouse.down() in the label, mouse.move() onto the box, mouse.up(), then assert aria-checked is still false.

  3. Nit: AGENTS.md (Commits and Pull Requests) asks the Test plan's ### After section to paste the actual command output rather than a summary of it.

: 'content';
};
const returnFocusAfterPress = () => {
const press = lastPress === 'none' ? releasedPress : lastPress;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: lastPress is only consumed here and by the root's pointerup/click listeners, so a press whose gesture ends with pointercancel (touch scroll, native drag) or outside the editor root stays 'content', and this now hands it to the next click — a click with no press behind it on the check mark is then ignored until the next press in the editor. Resetting lastPress and releasedPress on pointercancel, and honouring the content veto only for the click that directly follows the root's own pointerup, would avoid that.

Vedthakar and others added 3 commits November 16, 2026 18:54
…er checks the item

The click and pointerup handlers decided on the release position only, and
the pointerup consumed the recorded press before the click ran. A text
selection started in the item and released over the check mark therefore
toggled it. Keep the press of the gesture for its click and toggle only
when it wasn't on the item's content.

Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A press that ends in pointercancel (eg. a touch that becomes a scroll)
is followed by no release or click, so it stayed recorded and made the
next click with no press of its own skip the toggle.

Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Vedthakar

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Taken in the latest push: a press that ends in pointercancel is now forgotten, so it no longer vetoes a later click that has no press of its own. Added a unit test for it (touch pointerdown on the label, pointercancel, then a click on the check mark toggles); it fails without the change. I did not add an e2e test. Also rebased onto main and added a changeset.

— Ved Thakar

@rootnode-bot rootnode-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update — this looks good. Dragging a selection from a check list item's text onto its check box no longer checks the item, the new tests fail on main and pass here, and forgetting the press on pointercancel fixes the cancelled-touch case from the earlier round. A few optional, non-blocking suggestions:

  1. A press that ends outside the editor still vetoes the next press-less click (packages/lexical-list/src/checkList.ts, lines 313-327). lastPress is only consumed by the root's own pointerup/click listeners, so a selection dragged from an item's label and released outside the editor leaves it at 'content', and releasedPress lingers after a primary release that is followed by no click (for example a Control-click on macOS that opens the context menu). The next click with no press behind it on the check mark, the case the plugin's own comment and your screen-reader control test describe, is then ignored until the next press in the editor. Consuming the press from a capture pointerup on the root's owner document as well, and clearing releasedPress on contextmenu, would close both. Each is a short unit test next to the cancelled-press one: a press on the label, pointerup and click dispatched on an element outside the root, then a press-less click on the check mark should still toggle.

  2. Changeset: add a Verify: paragraph (.changeset/checklist-drag-release-no-toggle.md). CONTRIBUTING.md (Changesets) asks a fix that changes editing behaviour to say what to test, so it is listed under "Behavior changes", as the other check list fixes on main do. For example: Verify: in a check list, press in an item's text, drag onto its check mark and release; the item keeps its state and the text stays selected. A click on the check mark still toggles it.

  3. Consider a real-browser test as well. The new tests run in jsdom with hand-built events, so they cannot show that a browser delivers the click to the <li> at the release point. AGENTS.md (Testing Strategy) puts behaviour that depends on real layout in browser or e2e tests, and packages/lexical-playground/__tests__/e2e/List.spec.mjs already drives check lists with page.mouse: mouse.down() in the label, mouse.move() onto the box, mouse.up(), then aria-checked stays false.

  4. Nits: "does not toggle the item on touch either" releases 190px from the press, so on main the swipe check already stops the touch pointerup and only the trailing click makes the test fail; and the Test plan's ### Before output shows 12 tests while the file now has 19, with ### After summarised rather than pasted, which AGENTS.md (Commits and Pull Requests) asks for.

Automated review (maintainer link)

configHandleClick(event);
const press = returnFocusAfterPress();
releasedPress = 'none';
if (press !== 'content') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: the cancelled-press case is fixed, but lastPress is still consumed only by these root listeners. A selection dragged from the label and released outside the editor delivers its pointerup and click outside the root, so lastPress stays 'content' and this skips the next press-less click on the check mark; releasedPress likewise lingers after a primary release with no click (a macOS Control-click). Consuming the press from a capture pointerup on the root's owner document as well, and clearing releasedPress on contextmenu, would cover both.

'@lexical/list': patch
---

[fix] A press on a check list item's text that is released over its check mark, such as a text selection dragged onto it, no longer toggles the item

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: CONTRIBUTING.md (Changesets) asks a fix that changes editing behaviour to add a Verify: paragraph, for example:

Verify: in a check list, press in an item's text, drag onto its check mark and release; the item keeps its state and the text stays selected. A click on the check mark still toggles it.

This branch was successfully deployed

2 active deployments
Preview – lexical — 0341ba91 Deployed Nov 16, 2026 by vercel[bot]
Preview – lexical-playground — 0341ba91 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Checklist item becomes completed when releasing the selection within the checklist item box

1 participant