Repository navigation
Toggle only the nested task whose checkbox was clicked - #95
Merged
Merged
Conversation
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.
Owner
|
Thanks @rudycelekli — clear write-up and a solid regression test. Merging! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
In a note's preview, a task nested under another task can't be toggled on its own:
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>ase.target, so both callonToggleTask. 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.taskComponentsis exported so the test can call the item handler directly.Test
apps/web/test/markdown-tasks.test.tscalls 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.tsexpected [ [ 1 ], [ +0 ] ] to deeply equal [ [ 1 ] ]. The parent line was toggled too.npm run typecheckand biome are clean inapps/web.