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

WIP: Add descriptions to register_block_pattern. #23070

Merged
merged 19 commits into from
Jul 6, 2020
Merged

WIP: Add descriptions to register_block_pattern. #23070

merged 19 commits into from
Jul 6, 2020

Conversation

carolinan
Copy link
Contributor

@carolinan carolinan commented Jun 10, 2020

Description

I have attempted to add descriptions to block patterns.
Fixes #23042

I am also not sure if I got the ID right.

const descriptionId = block-editor-inserter__patterns-item-description-${ instanceId };

Output:
<div class="components-visually-hidden" id="block-editor-inserter__patterns-item-description-4">A cover block with a gradient background and a paragraph with an extra large font size.</div>

How has this been tested?

I added descriptions to four of the existing patterns, as well as a pattern inside a theme.
I tested it by checking the markup on the inserter, and tested the aria described by and visually hidden element with the NVDA screen reader.

Types of changes

New feature.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • [x ] My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

>
<BlockPreview blocks={ blocks } viewportWidth={ viewportWidth } />
<div className="block-editor-inserter__patterns-item-title">
{ pattern.title }
</div>
<VisuallyHidden id={ descriptionId }>
Copy link
Contributor

Choose a reason for hiding this comment

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

you can add

{ !! pattern.description && (
// Your visibily hidden element
} )

to render this conditionally depending on the presence of the description.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

This is looking good to me. I'd appreciate @enriquesanchez's review

@carolinan
Copy link
Contributor Author

How do you all feel about renaming "title" to label, matching register_block_style? Does it need to be a separate issue?

@youknowriad
Copy link
Contributor

We do have "title" for blocks too, so it seems the inconsistency already exists.

Adds doing_it_wrong messages for the required properties.
Adds descriptions to the block patterns.
Updates documentation with the description and viewportWidth.
@@ -15,16 +15,19 @@ The `register_block_pattern` function receives the name of the pattern as the fi
The properties of the pattern include:
- `title` (required): A human-readable title for the pattern.
- `content` (required): Raw HTML content for the pattern.
- `description` (required): A description of the pattern. Used to describe the pattern in the inserter.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm personally hesitant about making this required. I think it shouldn't be as a lot of existing patterns don't have it and we should fallback to the title. Sometimes the title is descriptive enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to not have it be required but be really really encouraged?

Copy link
Contributor

Choose a reason for hiding this comment

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

mmm I don't know, we could console log a message if we don't find it maybe but we never did that before and it can be very verbose. I can't think of a way though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is compatibility for existing patterns the only concern? Because the function was just renamed, developers had to make changes then, why is adding a description a bigger concern?

Copy link
Contributor

Choose a reason for hiding this comment

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

I've thought about this more and I still think it shouldn't be mandatory. Some patterns are descriptive enough and the API should be as straightforward to use as possible.

Enforcing on a potential Patterns directory/repository is a separate question though and I'd see this being different there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I thought that was the point, the patterns are not descriptive if you can't see them.
And currently, neither the title or the content is required, even though the documentation says they are.
Without a title, the only thing announced by screen readers is "button".

Adding a description is more straight forward than adding categories (especially if you throw in registering the categories).

@enriquesanchez
Copy link
Contributor

This is a great PR, @carolinan! Tested with VoiceOver + Safari and works as expected. The descriptions you added are very detailed and it's easy to picture the pattern.

@youknowriad
Copy link
Contributor

How can we move this PR forward to include in 5.5

@enriquesanchez
Copy link
Contributor

It'll be great to have this included with 5.5 and updated to reflect the changes in #23608.

Anything left to be done before we can merge?

@youknowriad
Copy link
Contributor

I'd personally like for the mandatory aspect to be removed to include this as stated here #23070 (comment) especially since we're late in the 5.5 process and people are likely to have created a lot of patterns by now.

@carolinan
Copy link
Contributor Author

So to summarize the discussion during the accessibility teams meeting on friday:
Title will be required.
Description will be strongly recommended.

#23608 needs to be merged first so that the list of patterns is up to date.

carolinan and others added 5 commits July 5, 2020 05:35
trying to solve merge conflicts with the inserter updates
Removes the check for the description property in the pattern registry.

Update the documentation to show that descriptions are encouraged, not required.
Adds the description to the block patterns list.
Outputs the visually hidden description after the title, if the description exists.
Updated the wording in the description for the viewportWidth.
@youknowriad
Copy link
Contributor

@carolinan That sounds great 👍

#23608 is merged, do you have time to refresh the PR to include in today's RC?

$message = __( 'Pattern content must be a string.', 'gutenberg' );
_doing_it_wrong( __METHOD__, $message, '8.5.0' );
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The change here needs dedicated Core patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Looks great. Thanks @carolinan

@youknowriad youknowriad merged commit cafa3fe into WordPress:master Jul 6, 2020
@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Jul 6, 2020
@github-actions github-actions bot added this to the Gutenberg 8.5 milestone Jul 6, 2020
@youknowriad
Copy link
Contributor

I merged too quickly without rewording the commit message. I guess it's fine for this time :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'description' property to block patterns
3 participants