Skip to content

Commit e3ebc6d

Browse files
authored
Border Controls: Display color indicator and check selected color (#34467)
* Fix border panel color indicator * Pass color value rather than slug as prop, to fix preset color preview * Lazily initialize state
1 parent 5d21c21 commit e3ebc6d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

packages/block-editor/src/hooks/border-color.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import classnames from 'classnames';
99
import { addFilter } from '@wordpress/hooks';
1010
import { __ } from '@wordpress/i18n';
1111
import { createHigherOrderComponent } from '@wordpress/compose';
12+
import { useState } from '@wordpress/element';
1213

1314
/**
1415
* Internal dependencies
@@ -48,8 +49,18 @@ export function BorderColorEdit( props ) {
4849
const colors = useSetting( 'color.palette' ) || EMPTY_ARRAY;
4950
const disableCustomColors = ! useSetting( 'color.custom' );
5051
const disableCustomGradients = ! useSetting( 'color.customGradient' );
52+
const [ colorValue, setColorValue ] = useState(
53+
() =>
54+
getColorObjectByAttributeValues(
55+
colors,
56+
borderColor,
57+
style?.border?.color
58+
)?.color
59+
);
5160

5261
const onChangeColor = ( value ) => {
62+
setColorValue( value );
63+
5364
const colorObject = getColorObjectByColorValue( colors, value );
5465
const newStyle = {
5566
...style,
@@ -71,7 +82,7 @@ export function BorderColorEdit( props ) {
7182
return (
7283
<ColorGradientControl
7384
label={ __( 'Color' ) }
74-
value={ borderColor || style?.border?.color }
85+
colorValue={ colorValue }
7586
colors={ colors }
7687
gradients={ undefined }
7788
disableCustomColors={ disableCustomColors }

packages/edit-site/src/components/sidebar/border-panel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default function BorderPanel( {
123123
{ hasBorderColor && (
124124
<ColorGradientControl
125125
label={ __( 'Color' ) }
126-
value={ borderColor }
126+
colorValue={ borderColor }
127127
colors={ colors }
128128
gradients={ undefined }
129129
disableCustomColors={ disableCustomColors }

0 commit comments

Comments
 (0)