Skip to content

Commit

Permalink
Support configuring z-index for popover (#231)
Browse files Browse the repository at this point in the history
* Support configuring z-index for popover

* bump version
  • Loading branch information
miafan23 authored Dec 5, 2024
1 parent 0ee57c7 commit 00dc917
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
## Changelog

## 2.15.0

- [feature] support configuring z-index for Popover component
- [fix] change default z-index value of Modal component to auto

## 2.14.0

- [feature] support configuring z-index for Modal component

## 2.13.0

- [feature] add prop exitOnUnderlayClicked to Modal component

## 2.12.0

- [feature] add possibility to pass onCopy to Copiable component

## 2.11.0

- [feature] support onOpenChange handler for contextMenu

## 2.10.2

- [feature] upgrade @mapbox/mbx-assembly to 1.6.0

## 2.10.0
- [feature] upgrade to react 18

- [feature] upgrade to react 18

## 2.9.0

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mr-ui",
"version": "2.14.0",
"version": "2.15.0",
"description": "UI components for Mapbox projects",
"main": "index.js",
"homepage": "./",
Expand Down
4 changes: 2 additions & 2 deletions src/components/modal/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface Props {
size?: 'small' | 'large' | 'auto';
padding?: 'large' | 'none';
margin?: 'large' | 'default';
zIndex?: number;
zIndex?: number | string;
onExit?: () => void;
exitOnUnderlayClicked?: boolean;
allowEventBubbling?: boolean;
Expand Down Expand Up @@ -54,7 +54,7 @@ export default function Modal({
size = 'large',
padding = 'large',
margin = 'default',
zIndex = 0,
zIndex = 'auto',
allowEventBubbling = false,
exitOnUnderlayClicked = true,
initialFocus,
Expand Down
6 changes: 1 addition & 5 deletions src/components/popover/examples/popover-a.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import Popover from '../popover';
export default function Example(): ReactElement {
const [open, setOpen] = useState(false);

const renderPopover = (
<div>
This is a popover.
</div>
);
const renderPopover = <div>This is a popover.</div>;

return (
<Popover
Expand Down
35 changes: 25 additions & 10 deletions src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface Props {
coloring?: 'light' | 'dark' | 'warning' | 'error';
placement?: 'top' | 'bottom' | 'left' | 'right';
alignment?: 'center' | 'start' | 'end';
zIndex?: number | string;
hasPointer?: boolean;
offsetFromAnchor?: number;
passthroughProps?: {
Expand All @@ -24,7 +25,7 @@ interface Props {
escapeCloses?: boolean;
hideWhenAnchorIsOffscreen?: boolean;
allowPlacementAxisChange?: boolean;
};
}

/**
* Display a popover. The popover is positioned relative to an anchor element
Expand All @@ -36,6 +37,7 @@ export default function Popover({
padding = 'medium',
active = false,
hasPointer = true,
zIndex = 'auto',
hideWhenAnchorIsOffscreen = false,
allowPlacementAxisChange = true,
clickOutsideCloses = true,
Expand All @@ -59,16 +61,19 @@ export default function Popover({
}
);

const bodyStyle = {
zIndex
};

const getContent = () => {
if (typeof content === 'function') {
return content();
}

return content;
}
};

const onDown = (e: Event) => {

// Don't call onExit if it wasn't provided.
if (!onExit) {
return;
Expand All @@ -87,19 +92,18 @@ export default function Popover({
}

onExit();
}
};

return (
<PopoverPrimitive.Root open={active}>
<span ref={triggerRef} style={{ display: 'contents' }}>
<PopoverPrimitive.Trigger asChild>
{children}
</PopoverPrimitive.Trigger>
<PopoverPrimitive.Trigger asChild>{children}</PopoverPrimitive.Trigger>
</span>
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content
sideOffset={offsetFromAnchor}
sideOffset={offsetFromAnchor}
className={bodyClasses}
style={bodyStyle}
onEscapeKeyDown={escapeCloses && onExit}
onPointerDownOutside={clickOutsideCloses && onDown}
onOpenAutoFocus={getInitialFocus}
Expand All @@ -111,7 +115,14 @@ export default function Popover({
{...passthroughProps}
>
{getContent()}
{hasPointer && <PopoverPrimitive.Arrow width={12} height={6} offset={6} fill={fill} />}
{hasPointer && (
<PopoverPrimitive.Arrow
width={12}
height={6}
offset={6}
fill={fill}
/>
)}
</PopoverPrimitive.Content>
</PopoverPrimitive.Portal>
</PopoverPrimitive.Root>
Expand Down Expand Up @@ -149,6 +160,10 @@ Popover.propTypes = {
* `'medium'`, `'small'`, or `'none'`.
*/
padding: PropTypes.oneOf(['medium', 'small', 'none']),
/**
* z-index of the popover.
*/
zIndex: PropTypes.number,
/**
* Whether or not the popover has a triangle pointer.
*/
Expand Down Expand Up @@ -195,5 +210,5 @@ Popover.propTypes = {
/**
* Props to pass directly to popover content options from `@radix-ui/react-popover`.
*/
passthroughProps: PropTypes.object,
passthroughProps: PropTypes.object
};

0 comments on commit 00dc917

Please sign in to comment.