feat: Add onLinkClick callback to TableOfContents component#437
feat: Add onLinkClick callback to TableOfContents component#437ainsleyclark merged 1 commit intomainfrom
Conversation
Adds an optional onLinkClick callback to TableOfContentsProps that is invoked when a TOC link is clicked, allowing consumers to close a sidebar or drawer on navigation. https://claude.ai/code/session_01TaD4iZDnbNnQqNr9TJGdRX
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Review summary
Small, well-scoped change that is idiomatic Svelte 5 and fully backward-compatible. The main gaps are the absence of component tests and a minor handler-attachment inefficiency. Critical issues 🔴None Warnings 🟡1. No tests for new behaviour 2. No-op handler always attached to every link onclick={onLinkClick ? (e) => onLinkClick(e, item) : undefined}This avoids attaching unnecessary DOM event handlers when the prop is absent. Suggestions 🟢1. Add @param tags to JSDoc /**
* Optional callback invoked when a TOC link is clicked.
* Useful for closing a sidebar or drawer on navigation.
* @param event - The native mouse event from the anchor click.
* @param item - The TOC item corresponding to the clicked link.
*/
onLinkClick?: (event: MouseEvent, item: TOCItem) => void;2. Document in the @component usage examples 3. Clarify preventDefault responsibility |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #437 +/- ##
==========================================
+ Coverage 64.59% 70.26% +5.67%
==========================================
Files 154 187 +33
Lines 6064 7439 +1375
==========================================
+ Hits 3917 5227 +1310
+ Misses 2064 2012 -52
- Partials 83 200 +117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Added an optional
onLinkClickcallback prop to the TableOfContents component, allowing consumers to respond to TOC link clicks with custom logic.Changes
onLinkClick?: (event: MouseEvent, item: TOCItem) => voidprop toTableOfContentsPropstypeonLinkClickfrom component propsImplementation Details
The callback is invoked via optional chaining (
onLinkClick?.(e, item)) on theonclickhandler of each TOC link, making it safe to use even when the prop is not provided. This enables use cases like closing a sidebar or drawer when navigating via TOC links.https://claude.ai/code/session_01TaD4iZDnbNnQqNr9TJGdRX