-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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, CustomGradientPicker, Dropdown: Fix positioning of popover when used in a dropdown #41361
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,11 @@ export default function Dropdown( props ) { | |
// This value is used to ensure that the dropdowns | ||
// align with the editor header by default. | ||
offset={ 13 } | ||
anchorRef={ ! hasAnchorRef ? containerRef : undefined } | ||
anchorRef={ | ||
! hasAnchorRef | ||
? containerRef?.current?.firstChild // Anchor to the rendered toggle. | ||
: undefined | ||
} | ||
Comment on lines
+111
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This always feels weird to me that the prop is called |
||
{ ...popoverProps } | ||
className={ classnames( | ||
'components-dropdown__content', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,11 +180,11 @@ const Popover = ( | |
__unstableForcePosition | ||
? undefined | ||
: size( { | ||
apply( { width, height } ) { | ||
apply( sizeProps ) { | ||
const { height } = sizeProps; | ||
if ( ! refs.floating.current ) return; | ||
|
||
// Reduce the height of the popover to the available space. | ||
Object.assign( refs.floating.current.firstChild.style, { | ||
maxWidth: `${ width }px`, | ||
maxHeight: `${ height }px`, | ||
overflow: 'auto', | ||
} ); | ||
|
@@ -194,6 +194,7 @@ const Popover = ( | |
shift( { | ||
crossAxis: true, | ||
limiter: limitShift(), | ||
padding: 1, // Necessary to avoid flickering at the edge of the viewport. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what it is about the particular settings we're using, but I couldn't get everything to work correctly (removed maxWidth on the size middleware, and a popover at the edge of the screen) without adding at least I'm hoping that adding |
||
} ), | ||
hasArrow ? arrow( { element: arrowRef } ) : undefined, | ||
].filter( ( m ) => !! m ); | ||
|
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.
This was throwing errors in Storybook due to
position
being undefined. To prevent those errors, I've added in optional chaining, which seemed to do the trick. It doesn't appear to change anything in real world usage in the editor, but made it easier to log out values while debugging in storybook.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.
When will it error in storybook? Are there reproduction steps?
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.
It was erroring when the component is first loaded if you navigate to
?path=/story/components-customgradientpicker--default
and open up the console. I think in the story for this component, when it's initially mounted it doesn't yet have any position settings which caused the issue. We should probably also update the story, but making this function a little more tolerant to empty values was a quick win 🙂