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: Improve empty block text #11560

Merged
merged 8 commits into from
Nov 8, 2018
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
2 changes: 1 addition & 1 deletion docs/design/block-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The most basic unit of the editor. The paragraph block is a simple input field.

### Placeholder:

- Simple placeholder text that says “Add text or type / to add content.” The placeholder disappears when the block is selected.
- Simple placeholder text that reads “Start writing or press / to insert a block”. The placeholder disappears when the block is selected.

### Selected state:

Expand Down
2 changes: 1 addition & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
'disablePostFormats' => ! current_theme_supports( 'post-formats' ),
'titlePlaceholder' => apply_filters( 'enter_title_here', __( 'Add title', 'gutenberg' ), $post ),
'bodyPlaceholder' => apply_filters( 'write_your_story', __( 'Write your story', 'gutenberg' ), $post ),
'bodyPlaceholder' => apply_filters( 'write_your_story', __( 'Start writing or press / to insert a block', 'gutenberg' ), $post ),
'isRTL' => is_rtl(),
'autosaveInterval' => 10,
'maxUploadFileSize' => $max_upload_size,
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/paragraph/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ class ParagraphBlock extends Component {
onMerge={ mergeBlocks }
onReplace={ this.onReplace }
onRemove={ () => onReplace( [] ) }
placeholder={ placeholder || __( 'Add text or type / to add content' ) }
aria-label={ __( 'Empty block; type text or press the forward slash key to insert a block' ) }
Copy link
Member

Choose a reason for hiding this comment

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

should "type text" be replaced with "start writing"?

Copy link
Member Author

Choose a reason for hiding this comment

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

For a screen reader I actually think "type text" is better than "start writing".

placeholder={ placeholder || __( 'Start writing or press / to insert a block' ) }
/>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports[`core/paragraph block edit matches snapshot 1`] = `
<p
aria-autocomplete="list"
aria-expanded="false"
aria-label="Add text or type / to add content"
aria-label="Empty block; type text or press the forward slash key to insert a block"
aria-multiline="true"
class="wp-block-paragraph editor-rich-text__tinymce"
contenteditable="true"
Expand All @@ -28,7 +28,7 @@ exports[`core/paragraph block edit matches snapshot 1`] = `
<p
class="editor-rich-text__tinymce wp-block-paragraph"
>
Add text or type / to add content
Start writing or press / to insert a block
</p>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function DefaultBlockAppender( {
return null;
}

const value = decodeEntities( placeholder ) || __( 'Write your story' );
const value = decodeEntities( placeholder ) || __( 'Start writing or press / to insert a block' );

// The appender "button" is in-fact a text field so as to support
// transitions by WritingFlow occurring by arrow key press. WritingFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
readOnly={true}
role="button"
type="text"
value="Write your story"
value="Start writing or press / to insert a block"
/>
<WithSelect(WithDispatch(InserterWithShortcuts)) />
<WithSelect(IfCondition(Inserter))
Expand All @@ -42,7 +42,7 @@ exports[`DefaultBlockAppender should match snapshot 1`] = `
readOnly={true}
role="button"
type="text"
value="Write your story"
value="Start writing or press / to insert a block"
/>
<WithSelect(WithDispatch(InserterWithShortcuts)) />
<WithSelect(IfCondition(Inserter))
Expand Down
12 changes: 4 additions & 8 deletions packages/editor/src/components/post-text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Textarea from 'react-autosize-textarea';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import { Component, Fragment } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { withSelect, withDispatch } from '@wordpress/data';
Expand Down Expand Up @@ -65,13 +64,12 @@ export class PostTextEditor extends Component {

render() {
const { value } = this.state;
const { placeholder, instanceId } = this.props;
const decodedPlaceholder = decodeEntities( placeholder );
const { instanceId } = this.props;

return (
<Fragment>
<label htmlFor={ `post-content-${ instanceId }` } className="screen-reader-text">
{ decodedPlaceholder || __( 'Write your story' ) }
{ __( 'Type text or HTML' ) }
</label>
<Textarea
autoComplete="off"
Expand All @@ -80,7 +78,7 @@ export class PostTextEditor extends Component {
onBlur={ this.stopEditing }
className="editor-post-text-editor"
id={ `post-content-${ instanceId }` }
placeholder={ decodedPlaceholder || __( 'Write your story' ) }
placeholder={ __( 'Start writing with text or HTML' ) }
/>
</Fragment>
);
Expand All @@ -89,11 +87,9 @@ export class PostTextEditor extends Component {

export default compose( [
withSelect( ( select ) => {
const { getEditedPostContent, getEditorSettings } = select( 'core/editor' );
const { bodyPlaceholder } = getEditorSettings();
const { getEditedPostContent } = select( 'core/editor' );
return {
value: getEditedPostContent(),
placeholder: bodyPlaceholder,
};
} ),
withDispatch( ( dispatch ) => {
Expand Down