Skip to content

Commit

Permalink
GradientPicker: always render popover below control point, memoize po…
Browse files Browse the repository at this point in the history
…poverProps
  • Loading branch information
ciampo committed Aug 9, 2022
1 parent 16568ea commit 1d30a2a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
21 changes: 10 additions & 11 deletions packages/components/src/color-palette/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,16 @@ export function CustomColorPickerDropdown( {
popoverProps: receivedPopoverProps,
...props
} ) {
const popoverProps = {
__unstableShift: true,
// Open below the control point (centered aligned) when in the sidebar.
...( isRenderedInSidebar
? {
placement: 'bottom',
offset: 10,
}
: {} ),
...receivedPopoverProps,
};
// Open below the control point (centered aligned).
const popoverProps = useMemo(
() => ( {
__unstableShift: true,
placement: 'bottom',
offset: 8,
...receivedPopoverProps,
} ),
[ receivedPopoverProps ]
);

return (
<Dropdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ exports[`ColorPalette Dropdown should render it correctly 1`] = `
popoverProps={
Object {
"__unstableShift": true,
"offset": 8,
"placement": "bottom",
}
}
renderContent={[Function]}
Expand Down Expand Up @@ -736,6 +738,8 @@ exports[`ColorPalette should render a dynamic toolbar of colors 1`] = `
popoverProps={
Object {
"__unstableShift": true,
"offset": 8,
"placement": "bottom",
}
}
renderContent={[Function]}
Expand Down
13 changes: 5 additions & 8 deletions packages/components/src/custom-gradient-bar/control-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,13 @@ function ControlPointButton( { isOpen, position, color, ...additionalProps } ) {
}

function GradientColorPickerDropdown( { isRenderedInSidebar, ...props } ) {
const popoverProps = useMemo( () => {
const result = {
const popoverProps = useMemo(
() => ( {
className:
'components-custom-gradient-picker__color-picker-popover',
};
if ( ! isRenderedInSidebar ) {
result.placement = 'top';
}
return result;
}, [ isRenderedInSidebar ] );
} ),
[]
);
return (
<CustomColorPickerDropdown
isRenderedInSidebar={ isRenderedInSidebar }
Expand Down

0 comments on commit 1d30a2a

Please sign in to comment.