Skip to content

Commit

Permalink
Fix placeholder positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jun 27, 2017
1 parent b662b2e commit 212f395
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
17 changes: 13 additions & 4 deletions blocks/editable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,20 +434,21 @@ export default class Editable extends Component {

render() {
const {
tagName,
tagName: Tagname = 'div',
style,
value,
focus,
className,
inlineToolbar = false,
formattingControls,
placeholder,
inline,
} = this.props;

// Generating a key that includes `tagName` ensures that if the tag
// 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 key = [ 'editor', Tagname ].join();
const classes = classnames( className, 'blocks-editable' );

const formatToolbar = (
Expand All @@ -472,15 +473,23 @@ export default class Editable extends Component {
</div>
}
<TinyMCE
tagName={ tagName }
tagName={ Tagname }
getSettings={ this.getSettings }
onSetup={ this.onSetup }
style={ style }
defaultValue={ value }
isEmpty={ this.state.empty }
placeholder={ placeholder }
label={ placeholder }
key={ key }
/>
{ this.state.empty &&
<Tagname
className="blocks-editable__tinymce"
style={ style }
>
{ inline ? placeholder : <p>{ placeholder }</p> }
</Tagname>
}
</div>
);
}
Expand Down
14 changes: 10 additions & 4 deletions blocks/editable/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

.blocks-editable__tinymce {
margin: 0;
position: relative;

> p:empty {
min-height: $editor-font-size * $editor-line-height;
Expand Down Expand Up @@ -39,14 +40,19 @@
}

&[data-is-empty="true"] {
position: relative;
position: absolute;
top: 0;
width: 100%;
margin-top: 0;

& > p {
margin-top: 0;
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions blocks/editable/tinymce.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class TinyMCE extends Component {
}

render() {
const { tagName = 'div', style, defaultValue, placeholder } = this.props;
const { tagName, style, defaultValue, label } = 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 @@ -92,7 +92,7 @@ export default class TinyMCE extends Component {
suppressContentEditableWarning: true,
className: 'blocks-editable__tinymce',
style,
'data-placeholder': placeholder,
'aria-label': label,
}, children );
}
}
4 changes: 3 additions & 1 deletion blocks/library/cover-image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ registerBlockType( 'core/cover-image', {
formattingControls={ [] }
focus={ focus }
onFocus={ setFocus }
onChange={ ( value ) => setAttributes( { title: value } ) } />
onChange={ ( value ) => setAttributes( { title: value } ) }
inline
/>
) : null }
</section>
</section>,
Expand Down
2 changes: 1 addition & 1 deletion blocks/library/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ registerBlockType( 'core/quote', {
<Editable
tagName="footer"
value={ citation }
placeholder={ __( 'Add citation…' ) }
placeholder={ __( 'Add citation…' ) }
onChange={
( nextCitation ) => setAttributes( {
citation: nextCitation,
Expand Down

0 comments on commit 212f395

Please sign in to comment.