Skip to content

Commit

Permalink
Mobile - Highlight word - Fixes for iOS and color indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerardo Pacheco committed Nov 2, 2021
1 parent ab75228 commit 7a1b2cb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
20 changes: 19 additions & 1 deletion packages/format-library/src/text-color/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function TextColorEdit( {
const color = getActiveColors( value, name, colors )?.color;

return { color: color?.replace( ' ', '' ) };
} );
}, [ value, colors ] );

const hasColorsToChoose = ! isEmpty( colors ) || ! allowCustomControl;
if ( ! hasColorsToChoose && ! isActive ) {
Expand Down Expand Up @@ -95,5 +95,23 @@ export const textColor = {
style: 'style',
class: 'class',
},
/*
* Since this format relies on the <mark> tag, it's important to
* prevent the default yellow background color applied by most
* browsers. The solution is to detect when this format is used with a
* text color but no background color, and in such cases to override
* the default styling with a transparent background.
*
* @see https://github.com/WordPress/gutenberg/pull/35516
*/
__unstableFilterAttributeValue( key, value ) {
if ( key !== 'style' ) return value;
// We should not add a background-color if it's already set
if ( value && value.includes( 'background-color' ) ) return value;
const addedCSS = [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' );
// Prepend `addedCSS` to avoid a double `;;` as any the existing CSS
// rules will already include a `;`.
return value ? [ addedCSS, value ].join( ';' ) : addedCSS;
},
edit: TextColorEdit,
};
7 changes: 7 additions & 0 deletions packages/format-library/src/text-color/inline.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ function setColors( value, name, colorSettings, colors ) {
const classNames = [];
const attributes = {};

if ( backgroundColor ) {
styles.push( [ 'background-color', backgroundColor ].join( ':' ) );
} else {
// Override default browser color for mark element.
styles.push( [ 'background-color', 'rgba(0, 0, 0, 0)' ].join( ':' ) );
}

if ( color ) {
const colorObject = getColorObjectByColorValue( colorSettings, color );
if ( colorObject ) {
Expand Down
8 changes: 7 additions & 1 deletion packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,13 @@ export class RichText extends Component {
const isManual =
this.lastAztecEventType !== 'input' &&
this.props.value === this.value;
if ( hasChanged && isManual ) {
const isFormatChange =
this.lastAztecEventType === 'format change' &&
this.props.value !== this.value;
if (
( hasChanged && isManual ) ||
( this.isIOS && hasChanged && isFormatChange )
) {
const value = this.createRecord();
const activeFormats = getActiveFormats( value );
this.setState( { activeFormats } );
Expand Down
4 changes: 4 additions & 0 deletions packages/rich-text/src/get-format-colors.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export function getFormatColors( value, formats, colors ) {
format.forEach( ( currentFormat ) => {
if ( currentFormat?.type === FORMAT_TYPE ) {
const className = currentFormat?.attributes?.class;
currentFormat.attributes.style = currentFormat.attributes.style.replace(
' ',
''
);

className?.split( ' ' ).forEach( ( currentClass ) => {
const match = currentClass.match( REGEX_TO_MATCH );
Expand Down

0 comments on commit 7a1b2cb

Please sign in to comment.