Skip to content

Toggle only the nested task whose checkbox was clicked - #95

Merged
rociiu merged 1 commit into
rociiu:mainfrom
rudycelekli:fix/nested-task-toggle
Oct 26, 2026
Merged

rociiu merged 1 commit into
rociiu:mainfrom
rudycelekli:fix/nested-task-toggle

Conversation

@rudycelekli

Copy link
Copy Markdown
Contributor

Bug

In a note's preview, a task nested under another task can't be toggled on its own:

- [ ] Pack
  - [ ] Passport

Clicking the Passport checkbox ticks Pack too. The click bubbles from the child's <li> to the parent task's <li>. Both handlers see the same <input> as e.target, so both call onToggleTask. The toggle uses a functional state update, so both lines flip.

Fix

The list-item handler now toggles only when the clicked checkbox belongs to that item (target.closest("li") === e.currentTarget). Clicking the parent's own checkbox works as before. taskComponents is exported so the test can call the item handler directly.

Test

apps/web/test/markdown-tasks.test.ts calls the child item handler, then the parent item handler, with the same checkbox target, the way the browser bubbles the click. It expects only the child line to toggle.

cd apps/web && npx vitest run test/markdown-tasks.test.ts

  • Before the fix (current main plus the export): fails, expected [ [ 1 ], [ +0 ] ] to deeply equal [ [ 1 ] ]. The parent line was toggled too.
  • After the fix: passes. The full web suite passes (5 files, 21 tests), and npm run typecheck and biome are clean in apps/web.

In the note preview, clicking the checkbox of a task nested under another task also bubbled to the parent task's list item, which saw the same checkbox as its target and toggled too. The item now toggles only when the checkbox belongs to it.
@rociiu

rociiu commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thanks @rudycelekli — clear write-up and a solid regression test. Merging!

@rociiu
rociiu merged commit d3a050b into rociiu:main Oct 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants