Skip to content

Commit f64db2b

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 f64db2b

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

@@ -307,6 +312,29 @@ React.createElement(() => {
307312
});
308313
```
309314

315+
## z-index
316+
317+
By default, the Popover's `z-index` is `auto`, which means it participates in
318+
the stacking context of its nearest positioned ancestor. This works well in most
319+
cases, but can cause the Popover to appear behind other positioned elements such
320+
as sticky headers, fixed toolbars, or modals.
321+
322+
When that happens, set `--rui-Popover__z-index` to a numeric value high enough
323+
to place the Popover above the conflicting layer. The override can be applied
324+
globally or scoped to a specific context:
325+
326+
```css
327+
/* Global override */
328+
:root {
329+
--rui-Popover__z-index: 1000;
330+
}
331+
332+
/* Scoped override */
333+
.my-context {
334+
--rui-Popover__z-index: 1000;
335+
}
336+
```
337+
310338
## Controlled Popover
311339

312340
Popover API can be used to control visibility of Popover component. You need to
@@ -379,6 +407,7 @@ which enables [Advanced Positioning](#advanced-positioning).
379407
| `--rui-Popover__color` | Text color |
380408
| `--rui-Popover__background-color` | Background color |
381409
| `--rui-Popover__box-shadow` | Popover box shadow |
410+
| `--rui-Popover__z-index` | Popover z-index (default: `auto`) |
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)