Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-modal-manager] Added zIndex prop to handle nested modals. #2156

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`ApplicationLayout Snapshot Tests renders the ApplicationLayout with giv
<ModalManager
closeOnOutsideClick={false}
shouldTrapFocus={false}
zIndex="6000"
>
<withRouter(NavigationLayout)
config={
Expand Down Expand Up @@ -311,6 +312,7 @@ exports[`ApplicationLayout Snapshot Tests renders the ApplicationLayout with onl
<ModalManager
closeOnOutsideClick={false}
shouldTrapFocus={false}
zIndex="6000"
>
<withRouter(NavigationLayout)
config={
Expand Down Expand Up @@ -428,6 +430,7 @@ exports[`ApplicationLayout Snapshot Tests when given nav items with icons matche
<ModalManager
closeOnOutsideClick={false}
shouldTrapFocus={false}
zIndex="6000"
>
<withRouter(NavigationLayout)
config={
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* Changed
* Updated `terra-folder-tree` example styles.

* Changed
* Updated `terra-modal-manager` example to consume `zIndex` prop.

## 1.85.0 - (May 1, 2024)

* Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ const ModalManagerExample = ({ showDisclosureAccessory }) => (
Disclosure Accessory
</div>
) : undefined}
zIndex="7000"
>
<ContentComponent disclosureType="modal" />
</ModalManager>
Expand Down
3 changes: 3 additions & 0 deletions packages/terra-modal-manager/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Added `zIndex` prop to handle nested modals.

## 6.76.0 - (April 4, 2024)

* Changed
Expand Down
10 changes: 9 additions & 1 deletion packages/terra-modal-manager/src/ModalManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: '8000'.
saket2403 marked this conversation as resolved.
Show resolved Hide resolved
*/
zIndex: PropTypes.oneOf(zIndexes),
};

const defaultProps = {
shouldTrapFocus: false,
closeOnOutsideClick: false,
zIndex: '6000',
};

const heightFromSize = {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -120,6 +127,7 @@ class ModalManager extends React.Component {
ariaLabel={(headerDataForPresentedComponent) ? headerDataForPresentedComponent.title : customProps['aria-label'] || 'Modal'}
setModalFocusElementRef={this.setModalFocusElementRef}
shouldTrapFocus={shouldTrapFocus}
zIndex={zIndex}
>
<ContentContainer
fill
Expand Down
11 changes: 11 additions & 0 deletions packages/terra-modal-manager/tests/jest/ModalManager.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,15 @@ describe('ModalManager', () => {
);
expect(modalManager).toMatchSnapshot();
});

it('should render the ModalManager with custom zIndex', () => {
const modalManager = (
<ModalManager zIndex="7000">
<TestContainer />
</ModalManager>
);

const result = enzymeIntl.mountWithIntl(modalManager);
expect(result).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`ModalManager correctly applies the theme context className 1`] = `
<ModalManager
closeOnOutsideClick={false}
shouldTrapFocus={false}
zIndex="6000"
>
<withDisclosureManager(DisclosureManager)
render={[Function]}
Expand Down Expand Up @@ -102,6 +103,7 @@ exports[`ModalManager should disclose content in Modal 1`] = `
}
}
shouldTrapFocus={true}
zIndex="6000"
>
<withDisclosureManager(DisclosureManager)
render={[Function]}
Expand Down Expand Up @@ -1350,6 +1352,7 @@ exports[`ModalManager should render the ModalManager with custom props 1`] = `
}
}
shouldTrapFocus={false}
zIndex="6000"
>
<withDisclosureManager(DisclosureManager)
render={[Function]}
Expand Down Expand Up @@ -1437,6 +1440,124 @@ exports[`ModalManager should render the ModalManager with custom props 1`] = `
</ModalManager>
`;

exports[`ModalManager should render the ModalManager with custom zIndex 1`] = `
<ModalManager
closeOnOutsideClick={false}
intl={
Object {
"defaultFormats": Object {},
"defaultLocale": "en",
"formatDate": [Function],
"formatHTMLMessage": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatPlural": [Function],
"formatRelative": [Function],
"formatTime": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralFormat": [Function],
"getRelativeFormat": [Function],
},
"locale": "en",
"messages": null,
"now": [Function],
"onError": [Function],
"textComponent": "span",
"timeZone": null,
}
}
shouldTrapFocus={false}
zIndex="7000"
>
<withDisclosureManager(DisclosureManager)
render={[Function]}
supportedDisclosureTypes={
Array [
"modal",
]
}
trapNestedDisclosureRequests={true}
>
<DisclosureManager
render={[Function]}
supportedDisclosureTypes={
Array [
"modal",
]
}
trapNestedDisclosureRequests={true}
>
<div
className="container"
intl={
Object {
"defaultFormats": Object {},
"defaultLocale": "en",
"formatDate": [Function],
"formatHTMLMessage": [Function],
"formatMessage": [Function],
"formatNumber": [Function],
"formatPlural": [Function],
"formatRelative": [Function],
"formatTime": [Function],
"formats": Object {},
"formatters": Object {
"getDateTimeFormat": [Function],
"getMessageFormat": [Function],
"getNumberFormat": [Function],
"getPluralFormat": [Function],
"getRelativeFormat": [Function],
},
"locale": "en",
"messages": null,
"now": [Function],
"onError": [Function],
"textComponent": "span",
"timeZone": null,
}
}
>
<withDisclosureManager(Component)>
<Component
disclosureManager={
DisclosureManagerDelegateInstance {
"disclose": [Function],
}
}
>
<button
type="button"
>
Hello World
</button>
</Component>
</withDisclosureManager(Component)>
<AbstractModal
ariaLabel="Modal"
classNameModal="modal-manager"
classNameOverlay={null}
closeOnEsc={true}
closeOnOutsideClick={false}
isCalledFromNotificationDialog={false}
isFullscreen={false}
isOpen={false}
onRequestClose={[Function]}
role="dialog"
rootSelector="#root"
setModalFocusElementRef={[Function]}
shouldTrapFocus={false}
zIndex="7000"
/>
</div>
</DisclosureManager>
</withDisclosureManager(DisclosureManager)>
</ModalManager>
`;

exports[`ModalManager should render the ModalManager with defaults 1`] = `
<ModalManager
closeOnOutsideClick={false}
Expand Down Expand Up @@ -1468,6 +1589,7 @@ exports[`ModalManager should render the ModalManager with defaults 1`] = `
}
}
shouldTrapFocus={false}
zIndex="6000"
>
<withDisclosureManager(DisclosureManager)
render={[Function]}
Expand Down
Loading