Skip to content
Prev Previous commit
Fix pushing link colors and behaviors
  • Loading branch information
aaronrobertshaw authored and glendaviesnz committed Aug 10, 2023
commit 1fcce005c53792fc121e84aa039d34cba2dcdc1c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,30 @@ function useChangesToPush( name, attributes, userConfig ) {
? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`
: getValueFromObjectPath( attributes.style, path );

// Links only have a single support entry but have two element
// style properties, color and hover color. The following check
// will add the hover color to the changes if required.
if ( key === 'linkColor' ) {
const linkChanges = value ? [ { path, value } ] : [];
const hoverPath = [
'elements',
'link',
':hover',
'color',
'text',
];
const hoverValue = getValueFromObjectPath(
attributes.style,
hoverPath
);

if ( hoverValue ) {
linkChanges.push( { path: hoverPath, value: hoverValue } );
}

return linkChanges;
}

// The shorthand border styles can't be mapped directly as global
// styles requires longhand config.
if ( flatBorderProperties.includes( key ) && value ) {
Expand Down Expand Up @@ -284,6 +308,7 @@ function PushChangesToGlobalStylesControl( {
if ( changes.length === 0 && ! userHasEditedBehaviors ) {
return;
}

if ( changes.length > 0 ) {
const { style: blockStyles } = attributes;

Expand Down Expand Up @@ -339,8 +364,10 @@ function PushChangesToGlobalStylesControl( {
}
);
}

if ( userHasEditedBehaviors ) {
__unstableMarkNextChangeAsNotPersistent();
setAttributes( { behaviors: undefined } );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good potential follow-up here might be to consolidate the updating of attributes and snackbar notices for both styles and behaviours. To keep the scope of this PR manageable for testing I've opted against this larger refactor.

setBehavior( attributes.behaviors );
createSuccessNotice(
sprintf(
Expand Down