Skip to content

fix: emit forwarded content events once - #3252

Merged
zernonia merged 1 commit into
v2from
fix/popover-close-auto-focus-once
Nov 12, 2026
Merged

zernonia merged 1 commit into
v2from
fix/popover-close-auto-focus-once

Conversation

@zernonia

@zernonia zernonia commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

🔗 Linked issue

Part of #3248

❓ Type of change

  • 🐞 Bug fix (a non-breaking change that fixes an issue)

📚 Description

Cause. PopoverContent emitted closeAutoFocus twice per close. PopoverContentModal and PopoverContentNonModal bind useForwardPropsEmits(props, emits) on PopoverContentImpl, which already carries an onCloseAutoFocus handler that re-emits the event. Each of them also had an explicit @close-auto-focus listener that called emits('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:

Component Event emitted twice
PopoverContent (modal) closeAutoFocus, pointerDownOutside
PopoverContent (non-modal) closeAutoFocus, interactOutside
DatePickerContent, DateRangePickerContent openAutoFocus
NavigationMenuContent pointerDownOutside, focusOutside, interactOutside
MenuRootContentModal (modal DropdownMenu / ContextMenu / Menubar content) 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. openAutoFocus on 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

  • New tests fail before the fix (17 failed across the 5 test files) and pass after.
    • Popover: openAutoFocus / closeAutoFocus once 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 prevented closeAutoFocus that moves focus keeps it there; closeAutoFocus fires once when an open content is unmounted.
    • DatePicker / DateRangePicker: openAutoFocus once per open.
    • NavigationMenu: pointerDownOutside, focusOutside, interactOutside once.
    • Menu: focusOutside once on modal content, still prevented.
  • jsdom tests for Popover, Dialog, AlertDialog, FocusScope, DismissableLayer, DatePicker, DateRangePicker, NavigationMenu, Menu, DropdownMenu, ContextMenu, Menubar: 283 passed.
  • Browser tests for Popover, Dialog, FocusScope, NavigationMenu, Menu, DropdownMenu, DatePicker, DateRangePicker: 238 passed.
  • type-check, eslint on the changed files, build and size-limit pass (Popover 20.94 kB, Dialog 11.23 kB, Full library 167.87 kB).

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Corrected event notifications across date pickers, navigation menus, dropdown menus, and popovers so listeners are called once per relevant opening or outside interaction.
    • Modal dropdown menus remain open when focus moves outside, while preventing the outside-focus event.
    • Popovers now report open, close, and dismissal events consistently. Focus returns to the trigger on close unless close autofocus is prevented.

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]>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Date picker, menu, navigation menu, and popover content components change how they emit autofocus and outside-interaction events. New tests check event counts, dismissal behavior, and focus restoration.

Changes: Content Event Emission

Layer / File(s) Summary
Calendar autofocus events
packages/core/src/DatePicker/DatePickerContent.vue, packages/core/src/DatePicker/DatePicker.test.ts, packages/core/src/DateRangePicker/DateRangePickerContent.vue, packages/core/src/DateRangePicker/DateRangePicker.test.ts
Date picker content components no longer explicitly emit openAutoFocus. Tests check that listeners run once on each opening.
Menu and navigation outside interactions
packages/core/src/Menu/MenuRootContentModal.vue, packages/core/src/Menu/MenuContentEmits.test.ts, packages/core/src/NavigationMenu/NavigationMenuContent.vue, packages/core/src/NavigationMenu/NavigationMenu.test.ts
Menu content no longer explicitly emits focusOutside. Navigation menu content no longer explicitly emits outside-interaction events. Tests check event counts and modal content behavior.
Popover event and focus behavior
packages/core/src/Popover/PopoverContentModal.vue, packages/core/src/Popover/PopoverContentNonModal.vue, packages/core/src/Popover/Popover.test.ts
Popover content no longer explicitly emits selected close and outside-interaction events. Tests cover event counts, dismissal, focus restoration, and unmounting.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • Issue 3248: The Popover changes remove the explicit closeAutoFocus re-emission described in the issue. The issue’s other listed items are not addressed.
Merge Risk: Minimal · up to 264e8

This change stops duplicate event emissions from several content components, so listeners run once. No concrete merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: emit forwarded content events once" matches the main change. The PR removes explicit re-emits from content wrappers that already forward emits, so each consumer listener runs once. The…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix: emit forwarded content events once" matches the main change. The PR removes explicit re-emits from content wrappers that already forward emits, so each consumer listener runs once. The affected components are Popover, DatePicker, DateRangePicker, NavigationMenu, and modal Menu content, and the title describes this duplicate-emission fix accurately.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d36c6a3 and 264e8e7.

Files selected for processing: 11

  • packages/core/src/DatePicker/DatePicker.test.ts
  • packages/core/src/DatePicker/DatePickerContent.vue
  • packages/core/src/DateRangePicker/DateRangePicker.test.ts
  • packages/core/src/DateRangePicker/DateRangePickerContent.vue
  • packages/core/src/Menu/MenuContentEmits.test.ts
  • packages/core/src/Menu/MenuRootContentModal.vue
  • packages/core/src/NavigationMenu/NavigationMenu.test.ts
  • packages/core/src/NavigationMenu/NavigationMenuContent.vue
  • packages/core/src/Popover/Popover.test.ts
  • packages/core/src/Popover/PopoverContentModal.vue
  • packages/core/src/Popover/PopoverContentNonModal.vue
Files with no reviewable changes: 5

  • packages/core/src/Popover/PopoverContentNonModal.vue
  • packages/core/src/NavigationMenu/NavigationMenuContent.vue
  • packages/core/src/Popover/PopoverContentModal.vue
  • packages/core/src/DatePicker/DatePickerContent.vue
  • packages/core/src/DateRangePicker/DateRangePickerContent.vue

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/reka-ui@3252

commit: 264e8e7

@zernonia
zernonia merged commit 267ab8e into v2 Nov 12, 2026
9 checks passed
@zernonia
zernonia deleted the fix/popover-close-auto-focus-once branch November 12, 2026 12:27
praburangki pushed a commit to vinicunca/akar that referenced this pull request Nov 16, 2026
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
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.

1 participant