Skip to content

Commit

Permalink
Add more placeholders (#1485)
Browse files Browse the repository at this point in the history
It also fixes a bug where styles would be messed up if there is no placeholder.
  • Loading branch information
ellatrix authored Jun 28, 2017
1 parent 81ac2ab commit ecea4ef
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ export default class Editable extends Component {
// changes, we unmount and destroy the previous TinyMCE element, then
// mount and initialize a new child element in its place.
const key = [ 'editor', Tagname ].join();
const isPlaceholderVisible = placeholder && this.state.empty;
const classes = classnames( className, 'blocks-editable' );

const formatToolbar = (
Expand Down Expand Up @@ -478,11 +479,11 @@ export default class Editable extends Component {
onSetup={ this.onSetup }
style={ style }
defaultValue={ value }
isEmpty={ this.state.empty }
isPlaceholderVisible={ isPlaceholderVisible }
label={ placeholder }
key={ key }
/>
{ this.state.empty &&
{ isPlaceholderVisible &&
<Tagname
className="blocks-editable__tinymce"
style={ style }
Expand Down
2 changes: 1 addition & 1 deletion blocks/editable/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
background: $light-gray-400;
}

&[data-is-empty="true"] {
&[data-is-placeholder-visible="true"] {
position: absolute;
top: 0;
width: 100%;
Expand Down
7 changes: 4 additions & 3 deletions blocks/editable/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ export default class TinyMCE extends Component {
}

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

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

if ( ! isEqual( this.props.style, nextProps.style ) ) {
Expand Down
1 change: 1 addition & 0 deletions blocks/library/code/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ registerBlockType( 'core/code', {
<TextareaAutosize
value={ attributes.content }
onChange={ ( event ) => setAttributes( { content: event.target.value } ) }
placeholder={ __( 'Write code…' ) }
/>
);
},
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/cover-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ registerBlockType( 'core/cover-image', {
{ title || !! focus ? (
<Editable
tagName="h2"
placeholder={ __( 'Write title' ) }
placeholder={ __( 'Write title' ) }
value={ title }
focus={ focus }
onFocus={ setFocus }
Expand Down
1 change: 1 addition & 0 deletions blocks/library/heading/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ registerBlockType( 'core/heading', {
} ) );
} }
style={ { textAlign: align } }
placeholder={ __( 'Write heading…' ) }
/>,
];
},
Expand Down
2 changes: 2 additions & 0 deletions blocks/library/preformatted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ registerBlockType( 'core/preformatted', {
} }
focus={ focus }
onFocus={ setFocus }
placeholder={ __( 'Write preformatted text…' ) }
inline
/>
);
},
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/pullquote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ registerBlockType( 'core/pullquote', {
value: nextValue,
} )
}
placeholder={ __( 'Write Quote…' ) }
placeholder={ __( 'Write quote…' ) }
focus={ focus && focus.editable === 'value' ? focus : null }
onFocus={ ( props ) => setFocus( { ...props, editable: 'value' } ) }
className="blocks-pullquote__content"
Expand Down
3 changes: 2 additions & 1 deletion blocks/library/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,13 @@ registerBlockType( 'core/quote', {
onFocus={ ( props ) => setFocus( { ...props, editable: 'value' } ) }
onMerge={ mergeBlocks }
style={ { textAlign: align } }
placeholder={ __( 'Write quote…' ) }
/>
{ ( ( citation && citation.length > 0 ) || !! focus ) && (
<Editable
tagName="footer"
value={ citation }
placeholder={ __( 'Add citation…' ) }
placeholder={ __( 'Write citation…' ) }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation,
Expand Down

0 comments on commit ecea4ef

Please sign in to comment.