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

Fix placeholder positioning #1477

Merged
merged 1 commit into from
Jun 27, 2017
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
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should include a modifier class here so reading the stylesheet is more obvious the intention on the .blocks-editable__tinymce + .blocks-editable__tinymce styling.

style={ style }
>
{ inline ? placeholder : <p>{ placeholder }</p> }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious the a11y impact of having placeholder both as aria-label of the TinyMCE and as the content of the adjacent placeholder node. Should this be aria-hidden perhaps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question! What are your thoughts, @afercia?

</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