Skip to content

fix(Popover, Menubar): respect a prevented closeAutoFocus - #3283

Merged
zernonia merged 1 commit into
unovue:v2from
ValentinYoushkevich:fix/popover-menubar-prevented-close-auto-focus
Nov 19, 2026
Merged

zernonia merged 1 commit into
unovue:v2from
ValentinYoushkevich:fix/popover-menubar-prevented-close-auto-focus

Conversation

@ValentinYoushkevich

@ValentinYoushkevich ValentinYoushkevich commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Part of #3248

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

With modal on, calling preventDefault() in a closeAutoFocus handler does nothing: when the popover closes, focus still jumps back to the trigger. The non-modal Popover and Dialog leave focus alone in that case. This is one of the items in #3248.

The modal content handles the event with .prevent and then focuses the trigger without checking whether the listener had already prevented it. I wrapped that in if (!event.defaultPrevented), the same way DialogContentModal does. MenubarContent had the same problem, and there it even took focus back from wherever the listener had moved it, so I fixed it the same way.

Nothing changes if you don't listen to closeAutoFocus. The existing test only covered the non-modal case, so I extended it to both modes and added Menubar tests; they fail on v2.

Here's a playground on 2.11.0: open A, B and C and press Escape. A ends up on body, B and C jump back to their trigger.

📝 Checklist

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

A modal PopoverContent and MenubarContent moved focus back to the trigger
even when a closeAutoFocus listener had called preventDefault(). Only run
the default focus return when the event has not been prevented, as the
non-modal Popover and Dialog already do.
@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Menubar and modal Popover close handlers now skip trigger focus restoration when closeAutoFocus has already been prevented. Tests cover focus outcomes for Menubar and for modal and non-modal Popovers.

Changes: Close autofocus behavior

Layer / File(s) Summary
Respect prevented closeAutoFocus events
packages/core/src/Menubar/MenubarContent.vue, packages/core/src/Menubar/Menubar.test.ts, packages/core/src/Popover/PopoverContentModal.vue, packages/core/src/Popover/Popover.test.ts, packages/core/src/Popover/Popover.browser.test.ts
Menubar and modal Popover skip trigger focus restoration when closeAutoFocus is already prevented. Tests check Menubar focus behavior and prevented-event behavior across Popover close methods and modal modes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • unovue/reka-ui#3252: This PR changes the modal Popover closeAutoFocus listener path, which is also updated here.

Suggested reviewers: zernonia, yan-ad, mellkam

Merge Risk: Minimal · up to ac353

This fixes modal Popover and Menubar so they stop returning focus to the trigger when a closeAutoFocus listener prevents it. Behavior without a listener is unchanged. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two components changed (Popover and Menubar) and the behavior fixed (respecting a prevented closeAutoFocus). The changeset matches: modal PopoverContent and MenubarContent now skip…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the two components changed (Popover and Menubar) and the behavior fixed (respecting a prevented closeAutoFocus). The changeset matches: modal PopoverContent and MenubarContent now skip focus restoration when the event is already prevented, and tests cover this case.

Finishing Touches

Generate unit tests (beta)

  • 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

  • Source mode: Auto
  • Repository: unovue/reka-ui
  • Branch: v2
  • File: .coderabbit.yaml
  • Commit: a9873a0
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bee49192-f165-47fe-a3b1-7af487d4ceeb
Commits

Reviewing files that changed from the base of the PR and between a9873a0 and ac353d4.

Files selected for processing: 5

  • packages/core/src/Menubar/Menubar.test.ts
  • packages/core/src/Menubar/MenubarContent.vue
  • packages/core/src/Popover/Popover.browser.test.ts
  • packages/core/src/Popover/Popover.test.ts
  • packages/core/src/Popover/PopoverContentModal.vue

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

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: ac353d4

@zernonia
zernonia merged commit 9a7af68 into unovue:v2 Nov 19, 2026
8 checks passed
zernonia added a commit to kricsleo/reka-ui that referenced this pull request Nov 19, 2026
…-hide

Conflicts resolved:
- Popper/PopperContent.vue: keep v2's `scope` prop next to the internal `present` prop.
- Popover/PopoverContentImpl.vue: keep v2's useContentId/useContentMounted and `scope`.
- Popover/PopoverContentModal.vue: keep v2's prevented closeAutoFocus handling (unovue#3283) and
  hasFocusLeftScope check (unovue#3254) next to the `present` gated scroll lock and hideOthers.
- Dialog/Dialog.test.ts, Dialog/DialogContentImpl.vue: take v2. The suppression of
  closeAutoFocus on the final unmount of kept-mounted content is dropped: a kept-mounted
  layer must still fire it when it is unmounted (DialogKeptMounted.browser.test.ts).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants