Repository navigation
fix(modal): ESC closes only the top-most modal - #3352
Merged
Merged
Conversation
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 8db432d:
|
Keep only the most recently mounted ModalContent keydown handler active so one ESC closes one dialog at a time. Add a controlled nested-modal regression test. Fixes DouyinFE#3351
dvd233
force-pushed
the
fix/modal-esc-top-only
branch
from
September 10, 2026 05:32
5cbb623 to
8db432d
Compare
1 task done
semi-design
|
||||||||||||||||||||||||||||||
| Project |
semi-design
|
| Branch Review |
release
|
| Run status |
|
| Run duration | 08m 34s |
| Commit |
|
| Committer | SudoUser |
| View all properties for this run ↗︎ | |
| Test results | |
|---|---|
|
|
2
|
|
|
0
|
|
|
13
|
|
|
0
|
|
|
289
|
Upgrade your plan to view test results. | |
| View all changes introduced in this branch ↗︎ | |
Tests for review
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes #3351.
Every
ModalContentregisters its ownkeydownlistener ondocument. SincestopPropagation()cannot stop sibling listeners on the same node, a single ESC closed all open dialogs at once instead of only the top-most one.Changes:
packages/semi-foundation/modal/modalContentFoundation.ts: keep a module-level stack of the registeredhandleKeyDownhandlers (pushed on listener mount, removed on unmount).handleKeyDownnow only closes when the current modal's handler is the top of the stack, so ESC closes dialogs one at a time.packages/semi-ui/modal/__test__/modal.test.js: regression test — with two open modals, one ESC cancels only the inner (most recently mounted) one; after it unmounts, the next ESC reaches the outer one.How to verify
esc closes only the top-most modal when multiple are opencovers the stacked-modal behavior (fails before this change, passes after).closeOnEsc: falseis unchanged — such modals never enter the stack.Related Issue
Fixes #3351
Checklist
Changelog
🇨🇳 Chinese
🇺🇸 English