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

Apply placeholder on editable wrapper #758

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 4 additions & 3 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export default class Editable extends wp.element.Component {
formattingControls,
placeholder
} = this.props;
const { empty } = this.state;

// Generating a key that includes `tagName` ensures that if the tag
// changes, we unmount (+ destroy) the previous TinyMCE element, then
Expand All @@ -390,7 +391,9 @@ export default class Editable extends wp.element.Component {
);

return (
<div className={ classes }>
<div
className={ classes }
data-placeholder={ empty ? placeholder : null }>
{ focus &&
<Fill name="Formatting.Toolbar">
{ showAlignments &&
Expand Down Expand Up @@ -419,8 +422,6 @@ export default class Editable extends wp.element.Component {
settings={ {
forced_root_block: inline ? false : 'p'
} }
isEmpty={ this.state.empty }
placeholder={ placeholder }
key={ key } />
</div>
);
Expand Down
28 changes: 12 additions & 16 deletions blocks/editable/style.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
.blocks-editable {
position: relative;

&[data-placeholder]:before {
content: attr( data-placeholder );
position: absolute;
top: 50%;
right: 0;
left: 0;
transform: translateY( -50% );
text-align: center;
opacity: 0.5;
pointer-events: none;
}
}

.blocks-editable__tinymce {
Expand Down Expand Up @@ -39,17 +51,6 @@
code[data-mce-selected] {
background: $light-gray-400;
}

&[data-is-empty="true"] {
position: relative;
}

&[data-is-empty="true"]:before {
content: attr( data-placeholder );
opacity: 0.5;
pointer-events: none;
position: absolute;
}
}

.block-editable__inline-toolbar {
Expand All @@ -67,11 +68,6 @@ figcaption.blocks-editable__tinymce {
color: $dark-gray-100;
text-align: center;
font-size: $default-font-size;

&:before {
left: 50%;
transform: translateX( -50% );
}
}


Expand Down
13 changes: 2 additions & 11 deletions blocks/editable/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ export default class TinyMCE extends wp.element.Component {
return false;
}

componentWillReceiveProps( nextProps ) {
const isEmpty = String( nextProps.isEmpty );

if ( this.editorNode.getAttribute( 'data-is-empty' ) !== isEmpty ) {
this.editorNode.setAttribute( 'data-is-empty', isEmpty );
}
}

componentWillUnmount() {
if ( ! this.editor ) {
return;
Expand Down Expand Up @@ -55,7 +47,7 @@ export default class TinyMCE extends wp.element.Component {
}

render() {
const { tagName = 'div', style, defaultValue, placeholder } = this.props;
const { tagName = 'div', style, defaultValue } = this.props;

// If a default value is provided, render it into the DOM even before
// TinyMCE finishes initializing. This avoids a short delay by allowing
Expand All @@ -70,8 +62,7 @@ export default class TinyMCE extends wp.element.Component {
contentEditable: true,
suppressContentEditableWarning: true,
className: 'blocks-editable__tinymce',
style,
'data-placeholder': placeholder
style
}, children );
}
}