Skip to content

Commit feb44ab

Browse files
yogeshbhutkaryogeshbhutkarmirkaciampot-hamano
authored
Popover: Add virtual padding to prevent it from hitting the viewport edge (#69555)
* feat: introduce `overflowOffset` prop to control maximum height calculation * fix: set default value for `overflowOffset` prop in Popover component * chore: add changelog entry * fix: rename `overflowOffset` prop to `overflowOffsetY` for clarity * chore: update changelog to include `overflowOffsetY` prop for Popover component * fix: use `padding` instead of manual offset implementation * fix: add a static `8px` overflow padding * chore: move CHANGELOG * chore: update unit test snapshots * revert: restore changes made to snapshot file * fix: update maxHeight, maxWidth to accomodate overflowPadding * fix: remove maxWidth calculations * fix: use `padding` within `size` middleware * chore: move `CHANGELOG` to `Unreleased` section Co-authored-by: yogeshbhutkar <[email protected]> Co-authored-by: mirka <[email protected]> Co-authored-by: ciampo <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: stokesman <[email protected]> Co-authored-by: okmttdhr <[email protected]>
1 parent f207be9 commit feb44ab

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/components/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Enhancement
66

77
- `Guide`: Make next and previous button text customizable ([#69907](https://github.com/WordPress/gutenberg/pull/69907)).
8+
- `Popover`: Introduce a virtual padding of `8px` to prevent it from hitting the viewport edge ([#69555](https://github.com/WordPress/gutenberg/pull/69555)).
89

910
## 29.8.0 (2025-04-11)
1011

packages/components/src/popover/index.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ import { StyleProvider } from '../style-provider';
7171
*/
7272
export const SLOT_NAME = 'Popover';
7373

74+
/**
75+
* Virtual padding to account for overflow boundaries.
76+
*
77+
* @type {number}
78+
*/
79+
const OVERFLOW_PADDING = 8;
80+
7481
// An SVG displaying a triangle facing down, filled with a solid
7582
// color and bordered in such a way to create an arrow-like effect.
7683
// Keeping the SVG's viewbox squared simplify the arrow positioning
@@ -224,6 +231,7 @@ const UnforwardedPopover = (
224231
computedFlipProp && flipMiddleware(),
225232
computedResizeProp &&
226233
size( {
234+
padding: OVERFLOW_PADDING,
227235
apply( sizeProps ) {
228236
const { firstElementChild } = refs.floating.current ?? {};
229237

@@ -234,7 +242,10 @@ const UnforwardedPopover = (
234242

235243
// Reduce the height of the popover to the available space.
236244
Object.assign( firstElementChild.style, {
237-
maxHeight: `${ sizeProps.availableHeight }px`,
245+
maxHeight: `${ Math.max(
246+
0,
247+
sizeProps.availableHeight
248+
) }px`,
238249
overflow: 'auto',
239250
} );
240251
},

0 commit comments

Comments
 (0)