Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions packages/block-editor/src/hooks/border-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import classnames from 'classnames';
import { addFilter } from '@wordpress/hooks';
import { __ } from '@wordpress/i18n';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useState } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -56,15 +56,30 @@ export function BorderColorEdit( props ) {
( colors, origin ) => colors.concat( origin.colors ),
[]
);
const { color: customBorderColor } = style?.border || {};
const [ colorValue, setColorValue ] = useState(
() =>
getColorObjectByAttributeValues(
availableColors,
borderColor,
style?.border?.color
customBorderColor
)?.color
);

// Detect changes in the color attributes and update the colorValue to keep the
// UI in sync. This is necessary for situations when border controls interact with
// eachother: eg, setting the border width to zero causes the color and style
// selections to be cleared.
useEffect( () => {
setColorValue(
getColorObjectByAttributeValues(
availableColors,
borderColor,
customBorderColor
)?.color
);
}, [ borderColor, customBorderColor, availableColors ] );

const onChangeColor = ( value ) => {
setColorValue( value );

Expand Down