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

Fixed RichText placeholder whitespace. #5035

Merged
merged 1 commit into from
Feb 15, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions blocks/library/button/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`core/button block edit matches snapshot 1`] = `
aria-label="Add text…"
class="wp-block-button__link blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<span
class="blocks-rich-text__tinymce wp-block-button__link"
Expand Down
1 change: 1 addition & 0 deletions blocks/library/heading/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`core/heading block edit matches snapshot 1`] = `
aria-label="Write heading…"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<h2
class="blocks-rich-text__tinymce"
Expand Down
1 change: 1 addition & 0 deletions blocks/library/list/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`core/list block edit matches snapshot 1`] = `
aria-label="Write list…"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<ul
class="blocks-rich-text__tinymce"
Expand Down
1 change: 1 addition & 0 deletions blocks/library/paragraph/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exports[`core/paragraph block edit matches snapshot 1`] = `
aria-label="Add text or type / to add content"
class="wp-block-paragraph blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<p
class="blocks-rich-text__tinymce wp-block-paragraph"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`core/preformatted block edit matches snapshot 1`] = `
aria-label="Write preformatted text…"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<pre
class="blocks-rich-text__tinymce"
Expand Down
1 change: 1 addition & 0 deletions blocks/library/pullquote/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`core/pullquote block edit matches snapshot 1`] = `
aria-label="Write quote…"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<div
class="blocks-rich-text__tinymce"
Expand Down
1 change: 1 addition & 0 deletions blocks/library/quote/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports[`core/quote block edit matches snapshot 1`] = `
aria-label="Write quote…"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<div
class="blocks-rich-text__tinymce"
Expand Down
2 changes: 2 additions & 0 deletions blocks/library/text-columns/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`core/text-columns block edit matches snapshot 1`] = `
aria-label="New Column"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<p
class="blocks-rich-text__tinymce"
Expand All @@ -32,6 +33,7 @@ exports[`core/text-columns block edit matches snapshot 1`] = `
aria-label="New Column"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<p
class="blocks-rich-text__tinymce"
Expand Down
1 change: 1 addition & 0 deletions blocks/library/verse/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ exports[`core/verse block edit matches snapshot 1`] = `
aria-label="Write…"
class="blocks-rich-text__tinymce"
contenteditable="true"
data-is-placeholder-visible="true"
/>
<pre
class="blocks-rich-text__tinymce"
Expand Down
26 changes: 15 additions & 11 deletions blocks/rich-text/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Component, Children, createElement } from '@wordpress/element';
*/
import { diffAriaProps, pickAriaProps } from './aria';

const IS_PLACEHOLDER_VISIBLE_ATTR_NAME = 'data-is-placeholder-visible';
export default class TinyMCE extends Component {
componentDidMount() {
this.initialize();
Expand All @@ -28,13 +29,15 @@ export default class TinyMCE extends Component {
return false;
}

componentWillReceiveProps( nextProps ) {
const name = 'data-is-placeholder-visible';
const isPlaceholderVisible = String( !! nextProps.isPlaceholderVisible );

if ( this.editorNode.getAttribute( name ) !== isPlaceholderVisible ) {
this.editorNode.setAttribute( name, isPlaceholderVisible );
configureIsPlaceholderVisible( isPlaceholderVisible ) {
const isPlaceholderVisibleString = String( !! isPlaceholderVisible );
if ( this.editorNode.getAttribute( IS_PLACEHOLDER_VISIBLE_ATTR_NAME ) !== isPlaceholderVisibleString ) {
this.editorNode.setAttribute( IS_PLACEHOLDER_VISIBLE_ATTR_NAME, isPlaceholderVisibleString );
}
}

componentWillReceiveProps( nextProps ) {
this.configureIsPlaceholderVisible( nextProps.isPlaceholderVisible );

if ( ! isEqual( this.props.style, nextProps.style ) ) {
this.editorNode.setAttribute( 'style', '' );
Expand Down Expand Up @@ -93,7 +96,7 @@ export default class TinyMCE extends Component {
}

render() {
const { tagName = 'div', style, defaultValue, className } = this.props;
const { tagName = 'div', style, defaultValue, className, isPlaceholderVisible } = this.props;
const ariaProps = pickAriaProps( this.props );

// If a default value is provided, render it into the DOM even before
Expand All @@ -105,12 +108,13 @@ export default class TinyMCE extends Component {
}

return createElement( tagName, {
ref: ( node ) => this.editorNode = node,
contentEditable: true,
suppressContentEditableWarning: true,
...ariaProps,
className: classnames( className, 'blocks-rich-text__tinymce' ),
contentEditable: true,
[ IS_PLACEHOLDER_VISIBLE_ATTR_NAME ]: isPlaceholderVisible,
ref: ( node ) => this.editorNode = node,
style,
...ariaProps,
suppressContentEditableWarning: true,
}, children );
}
}