Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RichText: show boundary only with editable element focus #15466

Merged
merged 2 commits into from May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/block-editor/src/components/rich-text/editable.js
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
21 changes: 12 additions & 9 deletions packages/block-editor/src/components/rich-text/index.js
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,15 +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' );

globalStyle.innerHTML =
`*:focus ${ boundarySelector }{background-color: ${ newColor }}`;
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