Skip to content

fix: close only the topmost modal on Escape#22168

Merged
heloiselui merged 1 commit into
carbon-design-system:mainfrom
adamalston:20426-modal
May 8, 2026
Merged

fix: close only the topmost modal on Escape#22168
heloiselui merged 1 commit into
carbon-design-system:mainfrom
adamalston:20426-modal

Conversation

@adamalston

@adamalston adamalston commented May 4, 2026

Copy link
Copy Markdown
Contributor

Closes #20426

Closed only the topmost modal on Escape.

Changelog

Changed

  • Closed only the topmost modal on Escape.

Testing / Reviewing

I wasn't sure where to abstract the util to, so I put it in packages/react/src/components/Modal/isTopmostVisibleModal.ts. If there's a preference to put it in packages/react/src/internal or elsewhere, let me know.

yarn test packages/react/src/components/ComposedModal
yarn test packages/react/src/components/Modal

PR Checklist

As the author of this PR, before marking ready for review, confirm you:

  • Reviewed every line of the diff
  • Updated documentation and storybook examples
  • Wrote passing tests that cover this change
  • Addressed any impact on accessibility (a11y)
  • Tested for cross-browser consistency
  • Validated that this code is ready for review and status checks should pass

More details can be found in the pull request guide

@netlify

netlify Bot commented May 4, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-react ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 4e85cce
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-react/deploys/69f7f69b2f646c00089107d5
😎 Deploy Preview https://deploy-preview-22168--v11-carbon-react.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented May 4, 2026

Copy link
Copy Markdown

Deploy Preview for v11-carbon-web-components ready!

Name Link
🔨 Latest commit 4e85cce
🔍 Latest deploy log https://app.netlify.com/projects/v11-carbon-web-components/deploys/69f7f69baa0f90000804e31d
😎 Deploy Preview https://deploy-preview-22168--v11-carbon-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.10%. Comparing base (cb81d31) to head (4e85cce).
⚠️ Report is 27 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #22168   +/-   ##
=======================================
  Coverage   95.10%   95.10%           
=======================================
  Files         548      548           
  Lines       45599    45605    +6     
  Branches     6582     6552   -30     
=======================================
+ Hits        43367    43373    +6     
  Misses       2102     2102           
  Partials      130      130           
Flag Coverage Δ
main-packages 89.15% <100.00%> (+<0.01%) ⬆️
web-components 97.89% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sangeethababu9223 sangeethababu9223 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hi @adamalston,
Thanks for taking the time to look into this and for the work you’ve put into the PR.

I just wanted to share a bit of context that might be helpful here — this approach is quite similar to my earlier PR #21436, which we ultimately decided not to move forward with because it relied on a querySelector-based solution.

Following that, we created a research issue (#21650) to explore a more robust ref-based approach using a registration model. That research has since been completed and the issue is now closed with the findings documented.

We’ll be creating a follow-up issue for the implementation soon based on that direction — happy to continue the discussion there.

Following a discussion with the team, we’re okay to proceed with this approach for now. If any issues come up down the line, we can revisit this and consider one of the alternative solutions outlined in the research issue (#21650).

cc: @tay1orjones

@sangeethababu9223 sangeethababu9223 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@adamalston

Copy link
Copy Markdown
Contributor Author

Appreciate the context. If there's already a preferred direction based on the research in #21650, I'm also fine not proceeding with this pull request and waiting for that implementation instead.

@tay1orjones tay1orjones left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure relying on DOM order is robust enough since folks could technically portal the node into anywhere. but I think it's a decent stopgap for now as we consider a more robust approach @sangeethababu9223's been thinking about.

Ideally this will all be handled by the browser eventually with native <dialog> so something to just get by with for now seems prudent.

@tay1orjones tay1orjones added this pull request to the merge queue May 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks May 6, 2026
@heloiselui heloiselui added this pull request to the merge queue May 8, 2026
Merged via the queue into carbon-design-system:main with commit 9edbceb May 8, 2026
55 of 56 checks passed
@adamalston adamalston deleted the 20426-modal branch May 12, 2026 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pressing esc should only close a single/focused modal

4 participants