Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popover: Introduce overflowPadding prop to support adding an offset #69555

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- `useAutocomplete`: Fix autocomple UI flicker when deleting trigger prefix ([#69562](https://github.com/WordPress/gutenberg/pull/69562)).

### Enhancement

- `Popover`: Introduce `overflowPadding` prop to configure virtual padding around boundary for overflow detection ([#69555](https://github.com/WordPress/gutenberg/pull/69555)).

## 29.6.0 (2025-03-13)

### Enhancement
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const UnforwardedPopover = (
inline = false,
variant,
style: contentStyle,
overflowPadding = 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

@mirka I'm torn between a default of 0 and 8, what are your thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

The offset feature may be useful for certain things, but I just realized it doesn't really help in solving the actual UX issue that prompted this 🙈 #69553 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

You have a point! But specifically for the default value, I'm learning towards 0 as it wouldn't introduce any changes to existing Popover usages. WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

If it's purely for padding and not for addressing the original UX issue, then I think the default would have to be 0, yes.

I can't say without doing an audit, but I notice that there are a lot of popovers that become fullscreen (completely filling the viewport with no padding) on mobile widths. So we wouldn't want to mess up those instances, though I'm not immediately sure how those are implemented.


// Deprecated props
__unstableForcePosition,
Expand Down Expand Up @@ -223,6 +224,7 @@ const UnforwardedPopover = (
computedFlipProp && flipMiddleware(),
computedResizeProp &&
size( {
padding: overflowPadding,
apply( sizeProps ) {
const { firstElementChild } = refs.floating.current ?? {};

Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/popover/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* External dependencies
*/
import type { ReactNode, MutableRefObject, SyntheticEvent } from 'react';
import type { Placement } from '@floating-ui/react-dom';
import type { Padding, Placement } from '@floating-ui/react-dom';

type PositionYAxis = 'top' | 'middle' | 'bottom';
type PositionXAxis = 'left' | 'center' | 'right';
Expand Down Expand Up @@ -160,6 +160,12 @@ export type PopoverProps = {
* @default false
*/
inline?: boolean;
/**
* The virtual padding around the boundary to check for overflow.
*
* @default 0
*/
overflowPadding?: Padding;
// Deprecated props
/**
* Prevent the popover from flipping and resizing when meeting the viewport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ function DataviewsViewConfigDropdown() {
popoverProps={ {
...DATAVIEWS_CONFIG_POPOVER_PROPS,
id: popoverId,
overflowPadding: 16,
} }
renderToggle={ ( { onToggle, isOpen } ) => {
return (
Expand Down
Loading