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

Components: Allow style prop on Popover #64489

Merged
merged 9 commits into from
Aug 15, 2024
Merged
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
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
- `Composite`: improve Storybook examples and add interactive controls ([#64397](https://github.com/WordPress/gutenberg/pull/64397)).
- `TimePicker`: add `hideLabelFromVision` prop ([#64267](https://github.com/WordPress/gutenberg/pull/64267)).
- `DropdownMenuV2`: adopt elevation scale ([#64432](https://github.com/WordPress/gutenberg/pull/64432)).
- `Popover`: allow `style` prop usage ([#64489](https://github.com/WordPress/gutenberg/pull/64489)).


## 28.5.0 (2024-08-07)

Expand Down
12 changes: 9 additions & 3 deletions packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ const UnforwardedPopover = (
WordPressComponentProps< PopoverProps, 'div', false >,
// To avoid overlaps between the standard HTML attributes and the props
// expected by `framer-motion`, omit all framer motion props from popover
// props (except for `animate` and `children`, which are re-defined in `PopoverProps`).
keyof Omit< MotionProps, 'animate' | 'children' >
// props (except for `animate` and `children` which are re-defined in
// `PopoverProps`, and `style` which is merged safely).
keyof Omit< MotionProps, 'animate' | 'children' | 'style' >
>,
forwardedRef: ForwardedRef< any >
) => {
Expand All @@ -139,6 +140,7 @@ const UnforwardedPopover = (
shift = false,
inline = false,
variant,
style: contentStyle,

// Deprecated props
__unstableForcePosition,
Expand Down Expand Up @@ -370,6 +372,7 @@ const UnforwardedPopover = (
const animationProps: HTMLMotionProps< 'div' > = shouldAnimate
? {
style: {
...contentStyle,
...motionInlineStyles,
...style,
},
Expand All @@ -378,7 +381,10 @@ const UnforwardedPopover = (
}
: {
animate: false,
style,
style: {
...contentStyle,
...style,
},
};

// When Floating UI has finished positioning and Framer Motion has finished animating
Expand Down
34 changes: 34 additions & 0 deletions packages/components/src/popover/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,40 @@ describe( 'Popover', () => {
} );
} );

describe( 'style', () => {
it( 'outputs inline styles added through the style prop in addition to built-in popover positioning styles', async () => {
render(
<Popover
style={ { zIndex: 0 } }
data-testid="popover-element"
>
Hello
</Popover>
);
const popover = screen.getByTestId( 'popover-element' );

await waitFor( () => expect( popover ).toBeVisible() );
expect( popover ).toHaveStyle(
'position: absolute; top: 0px; left: 0px; z-index: 0;'
);
} );

it( 'is not possible to override built-in popover positioning styles via the style prop', async () => {
render(
<Popover
style={ { position: 'static' } }
data-testid="popover-element"
>
Hello
</Popover>
);
const popover = screen.getByTestId( 'popover-element' );

await waitFor( () => expect( popover ).toBeVisible() );
expect( popover ).not.toHaveStyle( 'position: static;' );
} );
} );

describe( 'focus behavior', () => {
it( 'should focus the popover container when opened', async () => {
render(
Expand Down
Loading