-
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
Fix: Custom color picker popover position #36965
Fix: Custom color picker popover position #36965
Conversation
Size Change: +213 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
b02675a
to
d39d1a0
Compare
@@ -135,7 +137,12 @@ export default function ColorPalette( { | |||
<VStack spacing={ 3 } className={ className }> | |||
{ ! disableCustomColors && ( | |||
<Dropdown | |||
contentClassName="components-color-palette__custom-color-dropdown-content" | |||
contentClassName={ classnames( |
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.
Could we just pass down a css class instead of introducing a new API?
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.
We would need add a property like customColorContentClassName, to ColorPalette, and ColorGradientPanels etc. A block wanting to have the color picker appear in the correct position would need to explicitly know the class to add.
It seems preferable to have a flag that changes the positioning behavior. The fact we use a class to do that is an implementation detail, e.g: on mobile, the way to do it may be different.
@@ -25,3 +25,10 @@ | |||
padding: 0; | |||
} | |||
} | |||
|
|||
@include break-medium() { | |||
.components-dropdown__content.components-color-palette__custom-color-dropdown-content.is-rendered-in-sidebar.is-from-top .components-popover__content { |
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 is really coupled with internal class names of other components. Do you think we could avoid them or extract them somehow?
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.
Here we are changing the position of a popover, I'm not sure how we can avoid relying on the classes the component defines. And unfortunately, this is not the first time we do it, searching for ".components-popover__content" on the codebase we find lots of matches used on each place we change something related to the popover, in some cases even outside the components package while on this case we are inside the components package.
It is not an ideal solution but it seems to be consistent with what we are doing on similar cases.
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.
The Popover component has logic in place to switch its position if there's not enough room in the canvas at the chosen one. Can't we just rely on this behavior and set the default position to the left instead of adding this weird prop everywhere.
Fixes #36542
Currently, the custom color picker popover appears over the sidebar on the block inspector and on the global styles.
This PR fixes the issue and makes the custom color picker appear on the side as shown on the screenshot below.
In order to fix the issue, we are introducing an experimental __experimentalCorrectPositionForSidebar flag, that when true applies a special positioning for the popover. We are adding an option flag and not using this behavior by default because the component may be used outside of a sidebar and in that case that behavior should not apply.
How has this been tested?
I verified that in all the following cases the custom color picker appears at the side of the sidebar:
Screenshots