Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
9ed2fb4
Add Popover component to @wordpress/ui
ciampo Mar 11, 2026
7f6f110
Add Storybook stories for Popover component
ciampo Mar 11, 2026
4ff1cf1
Add unit tests for Popover component
ciampo Mar 11, 2026
43b2955
Fix review issues in Popover component
ciampo Mar 11, 2026
d532896
Extend Popover Popup with additional props
ciampo Mar 11, 2026
7bfba39
Add stories and tests for new Popover props
ciampo Mar 11, 2026
a7aba5e
Fix Controlled story race condition
ciampo Mar 11, 2026
1eda379
Improve Modal story with interactive form content
ciampo Mar 11, 2026
1cbd98f
Fix Controlled story click-outside flicker
ciampo Mar 11, 2026
6096213
Simplify Controlled story with checkbox toggle
ciampo Mar 11, 2026
ce7f665
Use Popover.Title and Description consistently in stories
ciampo Mar 11, 2026
2f961be
Fix animations and add `animated` prop to Popover.Popup
ciampo Mar 11, 2026
ceb7188
Show all side × align combinations in Positioning story
ciampo Mar 11, 2026
eb025b8
Mirror legacy WithSlotOutsideIframe pattern in CrossIframe story
ciampo Mar 11, 2026
d5a808c
Fix require error in GenericIframe by using static import
ciampo Mar 11, 2026
bb4ffc5
Add CrossIframeWithSlotFill story demonstrating SlotFill pattern
ciampo Mar 11, 2026
1c17d3b
Use @wordpress/components SlotFill in CrossIframeWithSlotFill story
ciampo Mar 11, 2026
9d7c6f9
Set collisionBoundary in collision avoidance and cross-iframe stories
ciampo Mar 11, 2026
558cac8
Use args and disable hardcoded controls in Popover stories
ciampo Mar 11, 2026
bfc5a21
Improve Controlled and Modal stories args handling
ciampo Mar 12, 2026
18f09e0
Refactor Popover stories: args forwarding, utils extraction, z-index fix
ciampo Mar 12, 2026
60a8350
Align WithCustomZIndex story with Select component pattern
ciampo Mar 12, 2026
aeb4c32
Expose `anchor` prop on Popover.Popup
ciampo Mar 19, 2026
ed91d0d
Expose `openOnHover`, `delay`, and `closeDelay` props on Popover.Root
ciampo Mar 19, 2026
b66cab5
Add Popover.Backdrop sub-component
ciampo Mar 19, 2026
6f8dd1c
Alias Base UI positioner CSS variables with --wp-ui-popover-* prefix
ciampo Mar 19, 2026
04a0330
Add Storybook stories for new Popover features
ciampo Mar 19, 2026
60542d8
Fix: move openOnHover/delay/closeDelay to TriggerProps
ciampo Mar 19, 2026
5784436
Fix CHANGELOG.md placeholder PR number
ciampo Mar 31, 2026
d77d624
Remove built-in animation from Popover
ciampo Mar 31, 2026
78e0d0d
Remove CSS variable aliases, use Base UI variables directly
ciampo Mar 31, 2026
ef8359a
Remove Popover.Backdrop sub-component
ciampo Mar 31, 2026
7a1d66f
Add `backdrop` prop to Popover.Popup
ciampo Mar 31, 2026
ced4233
Fix Anchor story VirtualElement positioning in docs mode
ciampo Mar 31, 2026
0b75701
Popover.Popup: deprioritize close button for initial focus
ciampo Mar 31, 2026
9ab9ce9
Extract useDeprioritizedInitialFocus into shared utility
ciampo Mar 31, 2026
e1d3df9
Update CHANGELOG: move Popover to Unreleased, add shared hook entry
ciampo Mar 31, 2026
04ff1a8
Popover: use Text for Title/Description, require Title for accessibility
ciampo Mar 31, 2026
67c0b04
Popover: enrich JSDoc across all subcomponents
ciampo Mar 31, 2026
6ad1976
Popover: drop Storybook parameters.docs in favor of JSDoc
ciampo Mar 31, 2026
5d86895
Popover: derive InteractionType from public API, document style/class…
ciampo Mar 31, 2026
669aa15
Popover: fix ViewportConstrainedSize story, improve useMeasure
ciampo Mar 31, 2026
c1caa5b
Popover: add TODO for backdrop color token
ciampo Mar 31, 2026
6b0b046
Popover: add PopupProps JSDoc documenting style/className split
ciampo Mar 31, 2026
3be5ee0
Popover.Arrow: render default arrow SVG with proper positioning
ciampo Apr 1, 2026
b8e47fc
Popover.Popup: add border, increase default sideOffset
ciampo Apr 1, 2026
29c50ae
CHANGELOG: remove redundant enhancement entry for new component
ciampo Apr 1, 2026
4967044
Fix overlay storybook example
ciampo Apr 1, 2026
fdb22c0
Popover stories: add NoArrow example
ciampo Apr 1, 2026
3160f55
Popover.Popup: expose arrowPadding prop, default to 8
ciampo Apr 2, 2026
3298ab4
Popover: increase popup padding to lg, update title variant and margin
ciampo Apr 2, 2026
c55a81b
Popover stories: update WithCloseButton, add title spacing, document …
ciampo Apr 2, 2026
868b4e9
Popover stories: replace hardcoded spacing with WPDS gap tokens
ciampo Apr 2, 2026
65b3f09
Popover stories: add InfoTip example
ciampo Apr 2, 2026
58ef1f2
Popover stories: use plain button with Icon in InfoTip example
ciampo Apr 2, 2026
50be8ed
Popover stories: use aria-label for InfoTip trigger
ciampo Apr 2, 2026
e916d6b
Popover stories: fix InfoTip trigger focus outline
ciampo Apr 2, 2026
bf43cd4
Popover stories: use WPDS border-radius-sm token for InfoTip trigger
ciampo Apr 2, 2026
27da335
Popover stories: use WPDS cursor-control token for InfoTip trigger
ciampo Apr 2, 2026
5812506
Popover tests: strengthen accessibility and variant assertions
ciampo Apr 2, 2026
0bebc5f
Popover tests: improve matchers and async query patterns
ciampo Apr 2, 2026
11a06e8
Popover: derive InitialFocus type from Popover, document modal focus …
ciampo Apr 3, 2026
553bf3d
Popover: move modal/focus-trapping docs from Popup to Root
ciampo Apr 3, 2026
40168bc
Popover: pick modal prop directly from Base UI's Root.Props
ciampo Apr 3, 2026
4852686
CHANGELOG: move Popover entry to Unreleased section
ciampo Apr 3, 2026
fe1e3ad
Popover.Arrow: remove unnecessary inline SVG styles
ciampo Apr 3, 2026
b46121f
Popover.Popup: document arrowPadding default matching border-radius
ciampo Apr 3, 2026
196c19c
fix CHANGELOG order
ciampo Apr 8, 2026
43fb33e
Popover: remove redundant margins, explicit render/ref forwarding
ciampo Apr 8, 2026
7b4dc50
Popover: use VisuallyHidden render prop pattern in stories
ciampo Apr 8, 2026
846af7e
Popover: remove inline prop, document as consumer pattern
ciampo Apr 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
- `AlertDialog.Popup`: removed `loading` prop (async flows are now handled internally via `Promise`-returning `onConfirm`);
- `AlertDialog.Popup`: made `children` optional in favor of a new `description` prop, which describes the alert dialog semantically.

### Internal
### New Features

- `AlertDialog`: Rewrite internals to use Base UI's `AlertDialog` primitives directly instead of `Dialog` wrappers. Introduces an internal state machine for async confirm flows ([#76937](https://github.com/WordPress/gutenberg/pull/76937)).
- Add `Popover` primitive ([#76438](https://github.com/WordPress/gutenberg/pull/76438)).

### Bug Fixes

Expand All @@ -23,6 +23,10 @@

- Add defensive styles against global WordPress stylesheets like common.css and forms.css ([#76783](https://github.com/WordPress/gutenberg/pull/76783)).

### Internal

- `AlertDialog`: Rewrite internals to use Base UI's `AlertDialog` primitives directly instead of `Dialog` wrappers. Introduces an internal state machine for async confirm flows ([#76937](https://github.com/WordPress/gutenberg/pull/76937)).

## 0.10.0 (2026-04-01)

### New Features
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './icon';
export * from './icon-button';
export * from './link';
export * as Notice from './notice';
export * as Popover from './popover';
export * from './stack';
export * as Tabs from './tabs';
export * from './text';
Expand Down
49 changes: 49 additions & 0 deletions packages/ui/src/popover/arrow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Popover as _Popover } from '@base-ui/react/popover';
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import styles from './style.module.css';
import type { ArrowProps } from './types';

function DefaultArrowSvg( props: React.ComponentProps< 'svg' > ) {
return (
<svg
width="20"
height="10"
viewBox="0 0 20 10"
fill="none"
{ ...props }
>
<path
d="M20 10H0V8h1.465a4 4 0 0 0 2.676-1.027l5.19-4.388c.378-.341.96-.341 1.338 0l5.19 4.388A4 4 0 0 0 18.535 8H20z"
className={ styles[ 'arrow-fill' ] }
/>
<path
d="M10 3.097 4.81 7.486A5 5 0 0 1 1.465 8.77H0V8h1.465a4 4 0 0 0 2.676-1.027l5.19-4.388c.378-.341.96-.341 1.338 0l5.19 4.388A4 4 0 0 0 18.535 8H20v.77h-1.465a5 5 0 0 1-3.345-1.284z"
className={ styles[ 'arrow-stroke' ] }
/>
</svg>
);
}

/**
* Renders an optional arrow element that points toward the anchor.
*
* Must be placed inside `Popover.Popup`. The arrow automatically rotates
* to match the current placement side.
*/
const Arrow = forwardRef< HTMLDivElement, ArrowProps >( function PopoverArrow(
{ children, className, ...props },
ref
) {
return (
<_Popover.Arrow
ref={ ref }
className={ clsx( styles.arrow, className ) }
{ ...props }
>
{ children ?? <DefaultArrowSvg /> }
</_Popover.Arrow>
);
} );

export { Arrow };
24 changes: 24 additions & 0 deletions packages/ui/src/popover/close.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Popover as _Popover } from '@base-ui/react/popover';
import { forwardRef } from '@wordpress/element';
import type { CloseProps } from './types';

/**
* Renders a button that closes the popover when clicked.
*
* When the popover opens, initial focus skips this button in favor of
* the first interactive element inside the popup (unless `initialFocus`
* on `Popover.Popup` overrides this behavior).
*/
const Close = forwardRef< HTMLButtonElement, CloseProps >(
function PopoverClose( props, ref ) {
return (
<_Popover.Close
ref={ ref }
data-wp-ui-popover-close=""
{ ...props }
/>
);
}
);

export { Close };
100 changes: 100 additions & 0 deletions packages/ui/src/popover/context.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import {
createContext,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
} from '@wordpress/element';

/**
* Whether validation is enabled. This is a build-time constant that allows
* bundlers to tree-shake all validation code in production builds.
*/
const VALIDATION_ENABLED = process.env.NODE_ENV !== 'production';

type PopoverValidationContextType = {
registerTitle: ( element: HTMLElement | null ) => void;
};

const PopoverValidationContext = VALIDATION_ENABLED
? createContext< PopoverValidationContextType | null >( null )
: ( null as unknown as React.Context< PopoverValidationContextType | null > );

function usePopoverValidationContextDev() {
return useContext( PopoverValidationContext );
}

function usePopoverValidationContextProd() {
return null;
}

/**
* Hook to access the popover validation context.
* Returns null in production or if not within a Popover.Popup.
*/
export const usePopoverValidationContext = VALIDATION_ENABLED
? usePopoverValidationContextDev
: usePopoverValidationContextProd;

/**
* Development-only provider that tracks whether Popover.Title is rendered.
*/
function PopoverValidationProviderDev( {
children,
}: {
children: React.ReactNode;
} ) {
const titleElementRef = useRef< HTMLElement | null >( null );

const registerTitle = useCallback( ( element: HTMLElement | null ) => {
titleElementRef.current = element;
}, [] );

const contextValue = useMemo(
() => ( { registerTitle } ),
[ registerTitle ]
);

useEffect( () => {
const titleElement = titleElementRef.current;

if ( ! titleElement ) {
throw new Error(
'Popover: Missing <Popover.Title>. ' +
'For accessibility, every popover requires a title. ' +
'If needed, the title can be visually hidden but must not be omitted.'
);
}

const textContent = titleElement.textContent?.trim();
if ( ! textContent ) {
throw new Error(
'Popover: <Popover.Title> cannot be empty. ' +
'Provide meaningful text content for the popover title.'
);
}
}, [] );

return (
<PopoverValidationContext.Provider value={ contextValue }>
{ children }
</PopoverValidationContext.Provider>
);
}

function PopoverValidationProviderProd( {
children,
}: {
children: React.ReactNode;
} ) {
return <>{ children }</>;
}

/**
* Provider component that validates Popover.Title presence in development mode.
* In production, this component is a no-op and just renders children.
*/
export const PopoverValidationProvider = VALIDATION_ENABLED
? PopoverValidationProviderDev
: PopoverValidationProviderProd;
34 changes: 34 additions & 0 deletions packages/ui/src/popover/description.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Popover as _Popover } from '@base-ui/react/popover';
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import { Text } from '../text';
import styles from './style.module.css';
import type { DescriptionProps } from './types';

/**
* Renders an optional paragraph that describes the popover content.
*
* The rendered element is linked to the popup via `aria-describedby`.
* Uses the `body-md` text variant by default.
*/
const Description = forwardRef< HTMLParagraphElement, DescriptionProps >(
function PopoverDescription(
{ className, children, render, ...props },
ref
) {
return (
<Text
ref={ ref }
variant="body-md"
render={
<_Popover.Description render={ render } { ...props } />
Comment thread
ciampo marked this conversation as resolved.
Resolved
}
className={ clsx( styles.description, className ) }
>
{ children }
</Text>
);
}
);

export { Description };
9 changes: 9 additions & 0 deletions packages/ui/src/popover/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Arrow } from './arrow';
import { Close } from './close';
import { Description } from './description';
import { Popup } from './popup';
import { Root } from './root';
import { Title } from './title';
import { Trigger } from './trigger';

export { Arrow, Close, Description, Popup, Root, Title, Trigger };
106 changes: 106 additions & 0 deletions packages/ui/src/popover/popup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { Popover as _Popover } from '@base-ui/react/popover';
import clsx from 'clsx';
import { forwardRef } from '@wordpress/element';
import { useMergeRefs } from '@wordpress/compose';
import {
type ThemeProvider as ThemeProviderType,
privateApis as themePrivateApis,
} from '@wordpress/theme';
import { unlock } from '../lock-unlock';
import resetStyles from '../utils/css/resets.module.css';
import { useDeprioritizedInitialFocus } from '../utils/use-deprioritized-initial-focus';
import { PopoverValidationProvider } from './context';
import styles from './style.module.css';
import type { PopupProps } from './types';

const ThemeProvider: typeof ThemeProviderType =
unlock( themePrivateApis ).ThemeProvider;

const CLOSE_ATTR = 'data-wp-ui-popover-close';

/**
* Renders the floating popup container for the popover content.
*
* Handles portal rendering, positioning relative to the anchor, collision
* avoidance, focus management, and optional backdrop. Supply a `container`
* element for cross-document scenarios such as iframes.
*/
const Popup = forwardRef< HTMLDivElement, PopupProps >( function PopoverPopup(
{
align = 'center',
alignOffset,
anchor,
// Matches the popup's border-radius (--wpds-border-radius-md).
arrowPadding = 8,
Comment on lines +33 to +34

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tricky one to avoid hard-coding 🤔 I don't suppose there's an easy way to evaluate the actual token value in this context. Not a blocker, but may make future maintenance a bit harder, or if we add some theme configuration that affects radii.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. More than the token value, the correct solution would be to resolve the value of the border radius at runtime (and watch for changes), but that feels like an overengineered solution. For now, I made the comment even more explicit. We can evaluate more involved solutions if the need arises

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we got #76604 working, we would be able to to at least get that default 8 value from a canonical source though!

backdrop = false,
children,
className,
collisionAvoidance,
collisionBoundary,
collisionPadding,
container,
finalFocus,
initialFocus,
side = 'bottom',
sideOffset = 8,
sticky,
style,
variant = 'default',
...props
},
ref
) {
const { resolvedInitialFocus, popupRef } = useDeprioritizedInitialFocus( {
initialFocus,
deprioritizedAttribute: CLOSE_ATTR,
} );
const mergedPopupRef = useMergeRefs( [ ref, popupRef ] );

const backdropElement = backdrop ? (
<_Popover.Backdrop className={ styles.backdrop } />
) : null;

const positioner = (
<_Popover.Positioner
align={ align }
alignOffset={ alignOffset }
anchor={ anchor }
arrowPadding={ arrowPadding }
collisionAvoidance={ collisionAvoidance }
collisionBoundary={ collisionBoundary }
collisionPadding={ collisionPadding }
side={ side }
sideOffset={ sideOffset }
sticky={ sticky }
style={ style }
className={ clsx(
resetStyles[ 'box-sizing' ],
styles.positioner,
className
) }
>
<ThemeProvider>
Comment thread
ciampo marked this conversation as resolved.
Resolved
<_Popover.Popup
ref={ mergedPopupRef }
initialFocus={ resolvedInitialFocus }
finalFocus={ finalFocus }
className={ clsx( variant !== 'unstyled' && styles.popup ) }
{ ...props }
>
<PopoverValidationProvider>
{ children }
</PopoverValidationProvider>
</_Popover.Popup>
</ThemeProvider>
</_Popover.Positioner>
);

return (
<_Popover.Portal container={ container }>
{ backdropElement }
{ positioner }
</_Popover.Portal>
);
} );

export { Popup };
Loading
Loading