Skip to content

Commit 2996324

Browse files
committed
UI: Restore popup CSS workaround for focus trap
Revert the ThemeProvider hasLayoutBox follow-up and keep the temporary unlayered popup stylesheet override while we reassess the longer-term fix upstream. Made-with: Cursor
1 parent 912bee6 commit 2996324

12 files changed

Lines changed: 54 additions & 26 deletions

File tree

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
.root {
22
display: contents;
33
}
4-
5-
.has-layout-box {
6-
display: block;
7-
}

packages/theme/src/theme-provider.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export const ThemeProvider = ( {
4949
children,
5050
color = {},
5151
cursor,
52-
hasLayoutBox = false,
5352
isRoot = false,
5453
density,
5554
}: ThemeProviderProps ) => {
@@ -81,11 +80,7 @@ export const ThemeProvider = ( {
8180
data-wpds-theme-provider-id={ instanceId }
8281
data-wpds-root-provider={ isRoot }
8382
data-wpds-density={ density }
84-
className={
85-
hasLayoutBox
86-
? `${ styles.root } ${ styles[ 'has-layout-box' ] }`
87-
: styles.root
88-
}
83+
className={ styles.root }
8984
>
9085
<ThemeContext.Provider value={ contextValue }>
9186
{ children }

packages/theme/src/types.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,6 @@ export interface ThemeProviderProps extends ThemeProviderSettings {
5454
*/
5555
children?: ReactNode;
5656

57-
/**
58-
* Whether the ThemeProvider wrapper should generate a layout box instead of
59-
* using `display: contents`.
60-
*
61-
* This is useful for cases where descendants rely on visibility or layout
62-
* APIs that require an ancestor box to exist.
63-
*
64-
* @default false
65-
*/
66-
hasLayoutBox?: boolean;
67-
6857
/**
6958
* When a ThemeProvider is the root provider, it will apply its theming
7059
* settings also to the root document element (e.g. the html element).

packages/ui/src/alert-dialog/popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const Popup = forwardRef< HTMLDivElement, PopupProps >(
5151
className={ portalClassName }
5252
>
5353
<_AlertDialog.Backdrop className={ dialogStyles.backdrop } />
54-
<ThemeProvider hasLayoutBox>
54+
<ThemeProvider>
5555
<_AlertDialog.Popup
5656
ref={ ref }
5757
className={ clsx(

packages/ui/src/dialog/popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Popup = forwardRef< HTMLDivElement, PopupProps >( function DialogPopup(
4343
return (
4444
<_Dialog.Portal container={ container } className={ portalClassName }>
4545
<_Dialog.Backdrop className={ styles.backdrop } />
46-
<ThemeProvider hasLayoutBox>
46+
<ThemeProvider>
4747
<_Dialog.Popup
4848
ref={ mergedRef }
4949
className={ clsx(

packages/ui/src/dialog/style.module.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;
22

3+
/*
4+
* Base UI ≥1.4.0 uses checkVisibility() to detect tabbable elements.
5+
* checkVisibility() returns false for display:contents (no generated box),
6+
* which breaks the focus-trap when ThemeProvider wraps the popup.
7+
*
8+
* This rule must be unlayered to override ThemeProvider's unlayered
9+
* display:contents.
10+
*/
11+
[data-wpds-theme-provider-id]:has(> .popup) {
12+
display: block;
13+
}
14+
315
@layer wp-ui-components {
416
.backdrop {
517
position: fixed;

packages/ui/src/form/primitives/select/popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const Popup = forwardRef< HTMLDivElement, SelectPopupProps >(
3232
className
3333
) }
3434
>
35-
<ThemeProvider hasLayoutBox>
35+
<ThemeProvider>
3636
<_Select.Popup
3737
ref={ ref }
3838
className={ itemPopupStyles.popup }

packages/ui/src/popover/popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const Popup = forwardRef< HTMLDivElement, PopupProps >( function PopoverPopup(
7979
className
8080
) }
8181
>
82-
<ThemeProvider hasLayoutBox>
82+
<ThemeProvider>
8383
<_Popover.Popup
8484
ref={ mergedPopupRef }
8585
initialFocus={ resolvedInitialFocus }

packages/ui/src/popover/style.module.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
@layer wp-ui-utilities, wp-ui-components, wp-ui-compositions, wp-ui-overrides;
22

3+
/*
4+
* Base UI ≥1.4.0 uses checkVisibility() to detect tabbable elements.
5+
* checkVisibility() returns false for display:contents (no generated box),
6+
* which breaks the focus-trap when ThemeProvider wraps the popup.
7+
*
8+
* This rule must be unlayered to override ThemeProvider's unlayered
9+
* display:contents.
10+
*/
11+
[data-wpds-theme-provider-id]:has(> .popup) {
12+
display: block;
13+
}
14+
315
@layer wp-ui-components {
416
.positioner {
517
z-index: var(--wp-ui-popover-z-index, initial);

packages/ui/src/tooltip/popup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const Popup = forwardRef< HTMLDivElement, PopupProps >( function TooltipPopup(
4848
them;
4949
- remove the hardcoded `bg` setting from the `ThemeProvider` below
5050
*/ }
51-
<ThemeProvider color={ { bg: '#1e1e1e' } } hasLayoutBox>
51+
<ThemeProvider color={ { bg: '#1e1e1e' } }>
5252
<Tooltip.Popup
5353
ref={ ref }
5454
className={ styles.popup }

0 commit comments

Comments
 (0)