Skip to content

Commit

Permalink
Format library: fix unsetting highlight color
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 2, 2021
1 parent 97ca916 commit 713fc36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/format-library/src/text-color/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { removeFormat } from '@wordpress/rich-text';
*/
import { default as InlineColorUI, getActiveColors } from './inline';

export const transparentValue = 'rgba(0, 0, 0, 0)';

const name = 'core/text-color';
const title = __( 'Highlight' );

Expand All @@ -30,7 +32,7 @@ function getComputedStyleProperty( element, property ) {

if (
property === 'background-color' &&
value === 'rgba(0, 0, 0, 0)' &&
value === transparentValue &&
element.parentElement
) {
return getComputedStyleProperty( element.parentElement, property );
Expand All @@ -47,7 +49,7 @@ function fillComputedColors( element, { color, backgroundColor } ) {
return {
color: color || getComputedStyleProperty( element, 'color' ),
backgroundColor:
backgroundColor === 'rgba(0, 0, 0, 0)'
backgroundColor === transparentValue
? getComputedStyleProperty( element, 'background-color' )
: backgroundColor,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/format-library/src/text-color/inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import { textColor as settings } from './index';
import { textColor as settings, transparentValue } from './index';

function parseCSS( css = '' ) {
return css.split( ';' ).reduce( ( accumulator, rule ) => {
if ( rule ) {
const [ property, value ] = rule.split( ':' );
if ( property === 'color' ) accumulator.color = value;
if ( property === 'background-color' )
if ( property === 'background-color' && value !== transparentValue )
accumulator.backgroundColor = value;
}
return accumulator;
Expand Down

0 comments on commit 713fc36

Please sign in to comment.