Skip to content

Commit 0058b18

Browse files
authored
fix: DH-17454: Wrap Modal in SpectrumThemeProvider (#2169)
Wrap the `Modal` component attached to `document.body` in `SpectrumThemeProvider`. Had to add `zIndex: 0` and `position: relative` to the `SpectrumThemeProvider` to fix the issue with `DatePicker` popovers nested in the `Modal` rendering behind it. ![Screenshot 2024-07-23 at 4 35 35 PM](https://github.com/user-attachments/assets/1a860697-f4dd-4565-bf0e-6269f24a8723)
1 parent 7fb4f64 commit 0058b18

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

packages/components/src/modal/Modal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React, {
99
import ReactDOM from 'react-dom';
1010
import { CSSTransition } from 'react-transition-group';
1111
import ThemeExport from '../ThemeExport';
12+
import { SpectrumThemeProvider } from '../theme/SpectrumThemeProvider';
1213

1314
interface ModalProps {
1415
className?: string;
@@ -101,7 +102,9 @@ function Modal({
101102

102103
return element.current
103104
? ReactDOM.createPortal(
104-
<>
105+
// Without the zIndex and position props
106+
// the modal is rendered on top of nested DatePicker popovers
107+
<SpectrumThemeProvider isPortal zIndex={0} position="relative">
105108
<CSSTransition
106109
appear
107110
mountOnEnter
@@ -171,7 +174,7 @@ function Modal({
171174
</div>
172175
</div>
173176
</CSSTransition>
174-
</>,
177+
</SpectrumThemeProvider>,
175178
element.current
176179
)
177180
: null;

packages/components/src/theme/SpectrumThemeProvider.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export interface SpectrumThemeProviderProps {
99
isPortal?: boolean;
1010
theme?: Theme;
1111
colorScheme?: 'light' | 'dark';
12+
zIndex?: number;
13+
position?: 'static' | 'absolute' | 'fixed' | 'relative' | 'sticky';
1214
}
1315

1416
/**
@@ -23,6 +25,8 @@ export function SpectrumThemeProvider({
2325
isPortal = false,
2426
theme = themeDHDefault,
2527
colorScheme,
28+
zIndex,
29+
position,
2630
}: SpectrumThemeProviderProps): JSX.Element {
2731
// a unique ID is used per provider to force it to render the theme wrapper element inside portals
2832
// based on https://github.com/adobe/react-spectrum/issues/1697#issuecomment-999827266
@@ -34,6 +38,8 @@ export function SpectrumThemeProvider({
3438
UNSAFE_className="spectrum-theme-provider"
3539
theme={theme}
3640
colorScheme={colorScheme}
41+
zIndex={zIndex}
42+
position={position}
3743
data-unique-id={id}
3844
>
3945
{children}

0 commit comments

Comments
 (0)