Repository navigation
fix: emit forwarded content events once - #3252
Conversation
Content wrappers that bind the forwarded emits also re-emitted the same event from an explicit listener, so a consumer handler ran twice. - Popover: closeAutoFocus, pointerDownOutside (modal), interactOutside (non-modal) - DatePicker, DateRangePicker: openAutoFocus - NavigationMenu: pointerDownOutside, focusOutside, interactOutside - Menu (modal content): focusOutside Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
commit: |
Content wrappers that bind the forwarded emits also re-emitted the same event from an explicit listener, so a consumer handler ran twice. - Popover: closeAutoFocus, pointerDownOutside (modal), interactOutside (non-modal) - DatePicker, DateRangePicker: openAutoFocus - NavigationMenu: pointerDownOutside, focusOutside, interactOutside - Menu (modal content): focusOutside Co-authored-by: Claude <[email protected]> Upstream-Commit: 267ab8e7facca2fc89d56ea12fba3ad2f2c199b6
🔗 Linked issue
Part of #3248
❓ Type of change
📚 Description
Cause.
PopoverContentemittedcloseAutoFocustwice per close.PopoverContentModalandPopoverContentNonModalbinduseForwardPropsEmits(props, emits)onPopoverContentImpl, which already carries anonCloseAutoFocushandler that re-emits the event. Each of them also had an explicit@close-auto-focuslistener that calledemits('closeAutoFocus', event)again. Vue merges the two listeners into an array and calls both, so the consumer handler ran twice for every close, including the unmount of an open content.Fix. The explicit listeners keep their internal logic but no longer re-emit; the forwarded handler is the single emit. It is first in the merged listener array, so the consumer handler still runs before the internal focus return and
preventDefault()is still honoured.The same duplicate (explicit listener re-emitting an event the forwarded handlers already emit) was fixed everywhere it occurs:
PopoverContent(modal)closeAutoFocus,pointerDownOutsidePopoverContent(non-modal)closeAutoFocus,interactOutsideDatePickerContent,DateRangePickerContentopenAutoFocusNavigationMenuContentpointerDownOutside,focusOutside,interactOutsideMenuRootContentModal(modalDropdownMenu/ContextMenu/Menubarcontent)focusOutside(only reachable when the focus trap does not pull focus back first)Checked and not affected (they forward once and their internal listeners do not re-emit): Dialog, AlertDialog, Drawer, Menu non-modal and sub content, DropdownMenu, ContextMenu, Menubar, Select, Combobox, HoverCard, Tooltip.
openAutoFocuson Popover itself was emitted once already. Drawer is unchanged.No public props, emits or types change. The only observable difference is that these handlers run once instead of twice.
Verification
openAutoFocus/closeAutoFocusonce per cycle for modal and non-modal, closing by Escape, outside click and trigger click; dismiss events once; focus returns to the trigger by default; a preventedcloseAutoFocusthat moves focus keeps it there;closeAutoFocusfires once when an open content is unmounted.openAutoFocusonce per open.pointerDownOutside,focusOutside,interactOutsideonce.focusOutsideonce on modal content, still prevented.type-check, eslint on the changed files,buildandsize-limitpass (Popover 20.94 kB, Dialog 11.23 kB, Full library 167.87 kB).📝 Checklist
🤖 Generated with Claude Code
Summary by CodeRabbit