Skip to content

fix(Popover): better handle esc when dialog is open#4788

Open
eirikbacker wants to merge 5 commits intomainfrom
fix/popover-open-dialog-support
Open

fix(Popover): better handle esc when dialog is open#4788
eirikbacker wants to merge 5 commits intomainfrom
fix/popover-open-dialog-support

Conversation

@eirikbacker
Copy link
Copy Markdown
Contributor

Fix: Popover no longer closes on "Escape" when a Dialog element is open above it

@eirikbacker eirikbacker self-assigned this Apr 24, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

🦋 Changeset detected

Latest commit: c227c27

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@digdir/designsystemet-react Patch
@digdir/designsystemet Patch
@digdir/designsystemet-css Patch
@digdir/designsystemet-types Patch
@digdir/designsystemet-web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

Preview deployments for this pull request:

storybook - 24. Apr 2026 - 15:44

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the React Popover component’s Escape-key handling so it won’t close when another top-layer UI (notably an open Dialog) is above it, aligning behavior with expected top-layer semantics.

Changes:

  • Update Popover Escape-key handler to only close when the Popover is considered top-layer.
  • Add isTopLayer(...) helper to detect when a Dialog / other popover is above the current Popover.
  • Add Storybook scenarios for Dropdown involving adjacent dialogs and nested dropdowns, plus a changeset entry.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
packages/react/src/components/popover/popover.tsx Changes Escape handling to respect top-layer state and adds isTopLayer detection helper.
packages/react/src/components/dropdown/dropdown.stories.tsx Adds Storybook stories to exercise dialog adjacency and nested dropdown scenarios.
.changeset/strange-yaks-burn.md Adds a patch changeset describing the Popover Escape behavior fix.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react/src/components/popover/popover.tsx Outdated
Comment thread packages/react/src/components/popover/popover.tsx
Comment thread packages/react/src/components/popover/popover.tsx
Comment thread .changeset/strange-yaks-burn.md Outdated
eirikbacker and others added 2 commits April 24, 2026 15:41
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Collaborator

@mimarz mimarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for this? 🙏

@eirikbacker
Copy link
Copy Markdown
Contributor Author

Can we add a test for this? 🙏

Please do 🤗 but, we should find another way to handle this, using popover="auto" to let the browser handle ESC-order as we can not 100% replicate the #top-layer computation anyway.

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.

4 participants