From d7176cc250e21360bbbb9c1ac197a919194ac1ca Mon Sep 17 00:00:00 2001
From: Saket Bajaj <42207428+saket2403@users.noreply.github.com>
Date: Wed, 8 May 2024 14:34:59 +0530
Subject: [PATCH] [terra-modal-manager] Added zIndex prop to handle nested
modals. (#2156)
---
.../ApplicationLayout.test.jsx.snap | 3 +
packages/terra-framework-docs/CHANGELOG.md | 3 +
.../example/ModalManagerExample.jsx | 1 +
packages/terra-modal-manager/CHANGELOG.md | 3 +
.../terra-modal-manager/src/ModalManager.jsx | 10 +-
.../tests/jest/ModalManager.test.jsx | 11 ++
.../__snapshots__/ModalManager.test.jsx.snap | 122 ++++++++++++++++++
7 files changed, 152 insertions(+), 1 deletion(-)
diff --git a/packages/terra-application-layout/tests/jest/__snapshots__/ApplicationLayout.test.jsx.snap b/packages/terra-application-layout/tests/jest/__snapshots__/ApplicationLayout.test.jsx.snap
index 2a975555b26..143f869ac20 100644
--- a/packages/terra-application-layout/tests/jest/__snapshots__/ApplicationLayout.test.jsx.snap
+++ b/packages/terra-application-layout/tests/jest/__snapshots__/ApplicationLayout.test.jsx.snap
@@ -4,6 +4,7 @@ exports[`ApplicationLayout Snapshot Tests renders the ApplicationLayout with giv
(
Disclosure Accessory
) : undefined}
+ zIndex="7000"
>
diff --git a/packages/terra-modal-manager/CHANGELOG.md b/packages/terra-modal-manager/CHANGELOG.md
index 3987e9258ca..9a5f34445fd 100644
--- a/packages/terra-modal-manager/CHANGELOG.md
+++ b/packages/terra-modal-manager/CHANGELOG.md
@@ -2,6 +2,9 @@
## Unreleased
+* Changed
+ * Added `zIndex` prop to handle nested modals.
+
## 6.76.0 - (April 4, 2024)
* Changed
diff --git a/packages/terra-modal-manager/src/ModalManager.jsx b/packages/terra-modal-manager/src/ModalManager.jsx
index e87beb5202a..e0373800951 100644
--- a/packages/terra-modal-manager/src/ModalManager.jsx
+++ b/packages/terra-modal-manager/src/ModalManager.jsx
@@ -15,6 +15,8 @@ export { disclosureType };
const cx = classNamesBind.bind(styles);
+const zIndexes = ['6000', '7000', '8000', '9000'];
+
const propTypes = {
/**
* The components to be rendered in the body of the ModalManager. These components will receive the
@@ -38,11 +40,16 @@ const propTypes = {
* If set to true, then the outside click will get enabled.
*/
closeOnOutsideClick: PropTypes.bool,
+ /**
+ * Z-Index layer to apply to the ModalContent and ModalOverlay. Valid values are the standard modal layer: '6000', and the max layer: '9000'.
+ */
+ zIndex: PropTypes.oneOf(zIndexes),
};
const defaultProps = {
shouldTrapFocus: false,
closeOnOutsideClick: false,
+ zIndex: '6000',
};
const heightFromSize = {
@@ -81,7 +88,7 @@ class ModalManager extends React.Component {
renderModal(manager) {
const {
- children, disclosureAccessory, withDisclosureContainer, shouldTrapFocus, closeOnOutsideClick, ...customProps
+ children, disclosureAccessory, withDisclosureContainer, shouldTrapFocus, closeOnOutsideClick, zIndex, ...customProps
} = this.props;
const theme = this.context;
@@ -120,6 +127,7 @@ class ModalManager extends React.Component {
ariaLabel={(headerDataForPresentedComponent) ? headerDataForPresentedComponent.title : customProps['aria-label'] || 'Modal'}
setModalFocusElementRef={this.setModalFocusElementRef}
shouldTrapFocus={shouldTrapFocus}
+ zIndex={zIndex}
>
{
);
expect(modalManager).toMatchSnapshot();
});
+
+ it('should render the ModalManager with custom zIndex', () => {
+ const modalManager = (
+
+
+
+ );
+
+ const result = enzymeIntl.mountWithIntl(modalManager);
+ expect(result).toMatchSnapshot();
+ });
});
diff --git a/packages/terra-modal-manager/tests/jest/__snapshots__/ModalManager.test.jsx.snap b/packages/terra-modal-manager/tests/jest/__snapshots__/ModalManager.test.jsx.snap
index 0b7aefc1f9b..b1d70e0b68e 100644
--- a/packages/terra-modal-manager/tests/jest/__snapshots__/ModalManager.test.jsx.snap
+++ b/packages/terra-modal-manager/tests/jest/__snapshots__/ModalManager.test.jsx.snap
@@ -11,6 +11,7 @@ exports[`ModalManager correctly applies the theme context className 1`] = `
`;
+exports[`ModalManager should render the ModalManager with custom zIndex 1`] = `
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+`;
+
exports[`ModalManager should render the ModalManager with defaults 1`] = `