Skip to content

Commit 39800ec

Browse files
committed
Support configuring z-index for popover
1 parent 0ee57c7 commit 39800ec

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

src/components/modal/modal.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Props {
1414
size?: 'small' | 'large' | 'auto';
1515
padding?: 'large' | 'none';
1616
margin?: 'large' | 'default';
17-
zIndex?: number;
17+
zIndex?: number | string;
1818
onExit?: () => void;
1919
exitOnUnderlayClicked?: boolean;
2020
allowEventBubbling?: boolean;
@@ -54,7 +54,7 @@ export default function Modal({
5454
size = 'large',
5555
padding = 'large',
5656
margin = 'default',
57-
zIndex = 0,
57+
zIndex = 'auto',
5858
allowEventBubbling = false,
5959
exitOnUnderlayClicked = true,
6060
initialFocus,
@@ -222,7 +222,7 @@ Modal.propTypes = {
222222
/**
223223
* z-index of the modal
224224
*/
225-
zIndex: PropTypes.number,
225+
zIndex: PropTypes.number || PropTypes.string,
226226
/**
227227
* The modal's primary action. If this is provided, an encouraging
228228
* button will be rendered at the bottom of the modal.

src/components/popover/examples/popover-a.tsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import Popover from '../popover';
77
export default function Example(): ReactElement {
88
const [open, setOpen] = useState(false);
99

10-
const renderPopover = (
11-
<div>
12-
This is a popover.
13-
</div>
14-
);
10+
const renderPopover = <div>This is a popover.</div>;
1511

1612
return (
1713
<Popover

src/components/popover/popover.tsx

+26-11
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface Props {
1313
coloring?: 'light' | 'dark' | 'warning' | 'error';
1414
placement?: 'top' | 'bottom' | 'left' | 'right';
1515
alignment?: 'center' | 'start' | 'end';
16+
zIndex?: number | string;
1617
hasPointer?: boolean;
1718
offsetFromAnchor?: number;
1819
passthroughProps?: {
@@ -24,7 +25,7 @@ interface Props {
2425
escapeCloses?: boolean;
2526
hideWhenAnchorIsOffscreen?: boolean;
2627
allowPlacementAxisChange?: boolean;
27-
};
28+
}
2829

2930
/**
3031
* Display a popover. The popover is positioned relative to an anchor element
@@ -36,6 +37,7 @@ export default function Popover({
3637
padding = 'medium',
3738
active = false,
3839
hasPointer = true,
40+
zIndex = 'auto',
3941
hideWhenAnchorIsOffscreen = false,
4042
allowPlacementAxisChange = true,
4143
clickOutsideCloses = true,
@@ -59,16 +61,19 @@ export default function Popover({
5961
}
6062
);
6163

64+
const bodyStyle = {
65+
zIndex
66+
};
67+
6268
const getContent = () => {
6369
if (typeof content === 'function') {
6470
return content();
6571
}
6672

6773
return content;
68-
}
74+
};
6975

7076
const onDown = (e: Event) => {
71-
7277
// Don't call onExit if it wasn't provided.
7378
if (!onExit) {
7479
return;
@@ -87,19 +92,18 @@ export default function Popover({
8792
}
8893

8994
onExit();
90-
}
95+
};
9196

9297
return (
9398
<PopoverPrimitive.Root open={active}>
9499
<span ref={triggerRef} style={{ display: 'contents' }}>
95-
<PopoverPrimitive.Trigger asChild>
96-
{children}
97-
</PopoverPrimitive.Trigger>
100+
<PopoverPrimitive.Trigger asChild>{children}</PopoverPrimitive.Trigger>
98101
</span>
99102
<PopoverPrimitive.Portal>
100103
<PopoverPrimitive.Content
101-
sideOffset={offsetFromAnchor}
104+
sideOffset={offsetFromAnchor}
102105
className={bodyClasses}
106+
style={bodyStyle}
103107
onEscapeKeyDown={escapeCloses && onExit}
104108
onPointerDownOutside={clickOutsideCloses && onDown}
105109
onOpenAutoFocus={getInitialFocus}
@@ -111,7 +115,14 @@ export default function Popover({
111115
{...passthroughProps}
112116
>
113117
{getContent()}
114-
{hasPointer && <PopoverPrimitive.Arrow width={12} height={6} offset={6} fill={fill} />}
118+
{hasPointer && (
119+
<PopoverPrimitive.Arrow
120+
width={12}
121+
height={6}
122+
offset={6}
123+
fill={fill}
124+
/>
125+
)}
115126
</PopoverPrimitive.Content>
116127
</PopoverPrimitive.Portal>
117128
</PopoverPrimitive.Root>
@@ -148,7 +159,11 @@ Popover.propTypes = {
148159
/**
149160
* `'medium'`, `'small'`, or `'none'`.
150161
*/
151-
padding: PropTypes.oneOf(['medium', 'small', 'none']),
162+
padding: PropTypes.oneOf(['medium', 'small', 'none'])
163+
/**
164+
* z-index of the popover.
165+
*/,
166+
zIndex: PropTypes.number || PropTypes.string,
152167
/**
153168
* Whether or not the popover has a triangle pointer.
154169
*/
@@ -195,5 +210,5 @@ Popover.propTypes = {
195210
/**
196211
* Props to pass directly to popover content options from `@radix-ui/react-popover`.
197212
*/
198-
passthroughProps: PropTypes.object,
213+
passthroughProps: PropTypes.object
199214
};

0 commit comments

Comments
 (0)