-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, and the tests look great! Thanks 🚀
/** | ||
* Inline styles to apply to the popover element. | ||
* | ||
* @default undefined | ||
*/ | ||
style?: React.CSSProperties; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we don't have to list this type explicitly, because it's already included as a div
prop via WordPressComponentProps
, and excluded from the MotionProps
omitting.
And I guess this comment can be a bit misleading:
// 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`, `children`, and `style`, which are // re-defined in `PopoverProps`).
Maybe "except for animate
and children
which are re-defined in PopoverProps
, and style
which is merged safely"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good - done in c811da6. Thanks for the quick review!
Flaky tests detected in c811da6. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10397832171
|
What?
In #64321 I have a use case for using the
style
prop on thePopover
component (see 'Why?').I discovered that you can use the
style
prop, but doing so clears the style properties set by floating-ui that position the popover because of the waycontentProps.style
(contentProps
collects the 'rest' of the component's attributes) overridesanimationProps.style
when the attributes are spread onto the component:gutenberg/packages/components/src/popover/index.tsx
Lines 401 to 402 in e076070
In this PR I'm making the
style
prop work correctly.How?
Spreads the
style
prop into theanimationProps.style
property, giving it lower precedence than other 'built-in' styles so that it isn't possible to break the popover's innate positioning.Why?
#64321 renders a popover inside the editor canvas iframe and requires overriding
margin
(which is added by the block layout system) andzIndex
(one of the popover's own styles). Due to the popover being inside the iframe, regular scss styles can't be used (they're not loaded in the iframe), so inline styles seem to be the obvious option.There are possible alternatives:
zIndex
from the iframe (e.g.noZIndex
), or allows setting a custom z index. Themargin
will still be overriden, but I can solve that by wrapping the popover in adiv
that hasstyle={{margin:0}}
specified. I'm not sure this solution is better than the one in this PR though, it adds an extra prop that's of limited use.Testing Instructions
A couple of unit tests have been added. I wasn't sure about adding a story for this - I thought it might be best to leave this prop undocumented just like the other html attributes that can be added via
...contentProps
.