Skip to content

Commit 743a677

Browse files
committed
Add z-index theme token and visibility to Popover placementStyle
- Add `--rui-Popover__z-index` token (default: `auto`) so consumers can control the Popover's stacking context without needing attribute selectors or class injection. - Allow `visibility` through `cleanPlacementStyle` so callers can hide the Popover before its initial position is computed (flash guard). - Document both additions in README Theming table and placementStyle prop JSDoc.
1 parent 3fd563d commit 743a677

6 files changed

Lines changed: 34 additions & 0 deletions

File tree

src/components/Popover/Popover.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Popover.propTypes = {
105105
top: PropTypes.string,
106106
'transform-origin': PropTypes.string,
107107
translate: PropTypes.string,
108+
visibility: PropTypes.string,
108109
}),
109110
/**
110111
* If set, the popover will become controlled, meaning it will be hidden by default and will need a trigger to open.

src/components/Popover/Popover.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@layer components.popover {
1414
.root {
1515
position: absolute;
16+
z-index: theme.$z-index;
1617
width: max-content;
1718
max-width: theme.$max-width;
1819
padding: theme.$padding;

src/components/Popover/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,15 @@ position the popover. The allowed props are:
178178
- `left`
179179
- `translate`
180180
- `transform-origin`
181+
- `visibility`
181182

182183
⚠️ [`inset`][mdn-inset] is a shorthand for `top right bottom left`, not for
183184
`inset-*` properties.
184185

186+
ℹ️ `visibility` can be used to hide the Popover before its initial position is
187+
computed, preventing a flash of the Popover in a wrong position. Set it to
188+
`hidden` initially, then remove or update it once the position is ready.
189+
185190
As opposed to `top right bottom left` and the `inset` shorthand, `inset-*`
186191
properties are writing-direction aware.
187192

@@ -379,6 +384,30 @@ which enables [Advanced Positioning](#advanced-positioning).
379384
| `--rui-Popover__color` | Text color |
380385
| `--rui-Popover__background-color` | Background color |
381386
| `--rui-Popover__box-shadow` | Popover box shadow |
387+
| `--rui-Popover__z-index` | Popover z-index (default: `auto`) |
388+
389+
### z-index
390+
391+
By default, the Popover's `z-index` is `auto`, which means it participates in
392+
the stacking context of its nearest positioned ancestor. This works well in most
393+
cases, but can cause the Popover to appear behind other positioned elements such
394+
as sticky headers, fixed toolbars, or modals.
395+
396+
When that happens, set `--rui-Popover__z-index` to a numeric value high enough
397+
to place the Popover above the conflicting layer. The override can be applied
398+
globally or scoped to a specific context:
399+
400+
```css
401+
/* Global override */
402+
:root {
403+
--rui-Popover__z-index: 1000;
404+
}
405+
406+
/* Scoped override */
407+
.my-context {
408+
--rui-Popover__z-index: 1000;
409+
}
410+
```
382411

383412
[div-attributes]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div#attributes
384413
[Floating UI]: https://floating-ui.com/docs/react-dom

src/components/Popover/_helpers/cleanPlacementStyle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default (placementStyle) => {
1212
'left',
1313
'translate',
1414
'transform-origin',
15+
'visibility',
1516
];
1617

1718
return Object.fromEntries(

src/components/Popover/_theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
@use "sass:math";
44

5+
$z-index: var(--rui-Popover__z-index);
56
$max-width: var(--rui-Popover__max-width);
67
$padding: var(--rui-Popover__padding);
78
$border-width: var(--rui-Popover__border-width);

src/theme.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,7 @@
10901090
--rui-Popover__color: var(--rui-color-text-primary);
10911091
--rui-Popover__background-color: var(--rui-color-background-layer-2);
10921092
--rui-Popover__box-shadow: var(--rui-shadow-layer-2);
1093+
--rui-Popover__z-index: auto;
10931094

10941095
//
10951096
// Tabs

0 commit comments

Comments
 (0)