-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
optional-multi-modal: Adding shouldReplaceExistingModal prop to mod…
#8489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…al manager. Adding a property (`shouldReplaceExistingMOdal`) to be used by modal manager that allow modals to be opened without closing other modals that may be opened. This works in a way similar to nesting modals in the DOM, but can be done programatically. The underlying change was to change the `current` modal in the modal manager to be an array, that way multiple modals can be rendered at a time instead of just one.
There was a problem hiding this 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 adds support for stacking multiple modals simultaneously in the Mantine modals manager by introducing a shouldReplaceExistingModal prop. By default, opening a new modal replaces the currently opened modal (maintaining backward compatibility), but setting shouldReplaceExistingModal: false allows multiple modals to be stacked on top of each other.
Key changes:
- The
currentstate in the modal reducer changed from a single modal to an array of modals to support multiple visible modals - Added
shouldReplaceExistingModalproperty toModalSettingstype - Updated modal rendering to iterate over all current modals with incremental z-index values
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/@mantine/modals/src/context.ts | Added shouldReplaceExistingModal optional property to ModalSettings type definition |
| packages/@mantine/modals/src/reducer.ts | Changed current from single modal to array; updated OPEN, CLOSE, CLOSE_ALL, and UPDATE actions to handle multiple modals |
| packages/@mantine/modals/src/ModalsProvider.tsx | Refactored modal rendering to map over state.current array with incremental z-index; extracted modal content logic into getModalContent callback |
| packages/@mantine/modals/src/use-modals/use-modals.test.tsx | Added comprehensive test suite covering backward compatibility, multiple modal stacking for all modal types, and mixed modal type scenarios |
| packages/@mantine/modals/src/Modals.story.tsx | Added interactive story demonstrating multiple stacked modals and mixed modal types |
| packages/@docs/demos/src/demos/modals/Modals.demo.multiple.tsx | Created new demo showcasing the multiple modals feature with code example |
| packages/@docs/demos/src/demos/modals/index.ts | Exported the new multiple demo |
| apps/mantine.dev/src/pages/x/modals.mdx | Added documentation section explaining the new feature with demo reference |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
It works incorrectly with escape key. When multiple modals are opened and escape key is pressed, the first one that closes is the underlying modal. See example of incorrect behavior on the video. Screen.Recording.2025-12-08.at.22.50.08.mov |
… into optional-multi-modal
… on stacked modals
…al manager.
Adding a property (
shouldReplaceExistingMOdal) to be used by modal manager that allow modals to be opened without closing other modals that may be opened. This works in a way similar to nesting modals in the DOM, but can be done programatically.The underlying change was to change the
currentmodal in the modal manager to be an array, that way multiple modals can be rendered at a time instead of just one.