Skip to content

Commit

Permalink
Use class
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed May 14, 2019
1 parent d5b5c44 commit 32436bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
15 changes: 11 additions & 4 deletions packages/block-editor/src/components/rich-text/editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ function applyInternetExplorerInputFix( editorNode ) {
}

const IS_PLACEHOLDER_VISIBLE_ATTR_NAME = 'data-is-placeholder-visible';
const CLASS_NAME = 'editor-rich-text__editable block-editor-rich-text__editable';

const oldClassName = 'editor-rich-text__editable';

export const className = 'block-editor-rich-text__editable';

/**
* Whether or not the user agent is Internet Explorer.
Expand Down Expand Up @@ -116,7 +119,11 @@ export default class Editable extends Component {
}

if ( ! isEqual( this.props.className, nextProps.className ) ) {
this.editorNode.className = classnames( nextProps.className, CLASS_NAME );
this.editorNode.className = classnames(
className,
oldClassName,
nextProps.className
);
}

const { removedKeys, updatedKeys } = diffAriaProps( this.props, nextProps );
Expand Down Expand Up @@ -156,7 +163,7 @@ export default class Editable extends Component {
style,
record,
valueToEditableHTML,
className,
className: additionalClassName,
isPlaceholderVisible,
...remainingProps
} = this.props;
Expand All @@ -166,7 +173,7 @@ export default class Editable extends Component {
return createElement( tagName, {
role: 'textbox',
'aria-multiline': true,
className: classnames( className, CLASS_NAME ),
className: classnames( className, oldClassName, additionalClassName ),
contentEditable: true,
[ IS_PLACEHOLDER_VISIBLE_ATTR_NAME ]: isPlaceholderVisible,
ref: this.bindEditorNode,
Expand Down
22 changes: 12 additions & 10 deletions packages/block-editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import Autocomplete from '../autocomplete';
import BlockFormatControls from '../block-format-controls';
import FormatEdit from './format-edit';
import FormatToolbar from './format-toolbar';
import Editable from './editable';
import Editable, { className as editableClassName } from './editable';
import { pickAriaProps } from './aria';
import { getPatterns } from './patterns';
import { withBlockEditContext } from '../block-edit/context';
Expand Down Expand Up @@ -502,16 +502,18 @@ export class RichText extends Component {
const boundarySelector = '*[data-rich-text-format-boundary]';
const element = this.editableRef.querySelector( boundarySelector );

if ( element ) {
const computedStyle = getComputedStyle( element );
const newColor = computedStyle.color
.replace( ')', ', 0.2)' )
.replace( 'rgb', 'rgba' );
const path = `[contenteditable]:focus ${ boundarySelector }`;
const rules = `{background-color: ${ newColor }}`;

globalStyle.innerHTML = path + rules;
if ( ! element ) {
return;
}

const computedStyle = getComputedStyle( element );
const newColor = computedStyle.color
.replace( ')', ', 0.2)' )
.replace( 'rgb', 'rgba' );
const selector = `.${ editableClassName }:focus ${ boundarySelector }`;
const rule = `background-color: ${ newColor }`;

globalStyle.innerHTML = `${ selector } {${ rule }}`;
}

/**
Expand Down

0 comments on commit 32436bc

Please sign in to comment.