fix: dropdown stays open when clicking Inertia Link items#32
fix: dropdown stays open when clicking Inertia Link items#32itsrafsanjani merged 1 commit intov1.xfrom
Conversation
…efault children Made-with: Cursor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem:
When a
DropdownItemwraps a child that callsevent.preventDefault()on click(e.g. an Inertia
<Link>), Headless UI's merged click handler detects the flag andbails out before invoking
close(). This leaves the dropdown menu open after theuser clicks an item.
Additionally, the render-prop API used the deprecated
activeprop from Headless UI v1.Changes:
src/Components/Dropdown/DropdownItem.tsx{ active }with{ focus, close }in theMenu.Itemrender prop —focusis the Headless UI v2 replacement for the deprecatedactiveprop.classNamecondition fromactive→focus.onClickCapture={close}to the wrapper<div>— the capture phase firesbefore any child handler can call
preventDefault(), guaranteeing the menu alwayscloses on click regardless of child behaviour.
Why
onClickCaptureinstead ofonClick:React's
onClickruns in the bubble phase. If a child callsevent.preventDefault()first, Headless UI's merged handler sees the flag and skips
close().onClickCaptureruns top-down (parent before child), so
close()is called unconditionally before thechild even sees the event.
Testing:
npm run build(tsc+ Vite) exits 0 with no type errors.<a>, an Inertia<Link>, and a button withevent.preventDefault().Summary by CodeRabbit