Skip to content

Commit

Permalink
First try for placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Apr 20, 2017
1 parent af45471 commit dbb6a10
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
20 changes: 11 additions & 9 deletions blocks/components/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export default class Editable extends wp.element.Component {
onSetup( editor ) {
this.editor = editor;
editor.on( 'init', this.onInit );
editor.on( 'focusout', this.onChange );
editor.on( 'NewBlock', this.onNewBlock );
editor.on( 'focusin', this.onFocus );
editor.on( 'input', this.onChange );
}

onInit() {
Expand All @@ -65,12 +65,13 @@ export default class Editable extends wp.element.Component {
}

onChange() {
if ( ! this.editor.isDirty() ) {
return;
if ( this.props.onChange ) {
const value = this.editor.getContent();

if ( value !== this.props.value ) {
this.props.onChange( value );
}
}
const value = this.editor.getContent();
this.editor.save();
this.props.onChange( value );
}

onNewBlock() {
Expand Down Expand Up @@ -155,14 +156,15 @@ export default class Editable extends wp.element.Component {
}

render() {
const { tagName: Tag = 'div', style, className } = this.props;
const classes = classnames( 'blocks-editable', className );
const { tagName: Tag = 'div', style, className, value, placeholder } = this.props;
const classes = classnames( 'blocks-editable', className, { 'is-empty': ! value } );

return (
<Tag
ref={ this.bindNode }
style={ style }
className={ classes } />
className={ classes }
placeholder={ placeholder } />
);
}
}
11 changes: 11 additions & 0 deletions blocks/components/editable/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
&:focus {
outline: none;
}

&.is-empty {
position: relative;
}

&.is-empty:before {
content: attr( placeholder );
opacity: 0.5;
pointer-events: none;
position: absolute;
}
}

0 comments on commit dbb6a10

Please sign in to comment.