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. |
mirka
left a comment
There was a problem hiding this comment.
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.
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.
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
styleprop on thePopovercomponent (see 'Why?').I discovered that you can use the
styleprop, but doing so clears the style properties set by floating-ui that position the popover because of the waycontentProps.style(contentPropscollects the 'rest' of the component's attributes) overridesanimationProps.stylewhen 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
styleprop work correctly.How?
Spreads the
styleprop into theanimationProps.styleproperty, 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:
zIndexfrom the iframe (e.g.noZIndex), or allows setting a custom z index. Themarginwill still be overriden, but I can solve that by wrapping the popover in adivthat 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.