-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
WIP: Add descriptions to register_block_pattern. #23070
Conversation
Adds visually hidden descriptions to block patterns in the inserter. For #23042.
> | ||
<BlockPreview blocks={ blocks } viewportWidth={ viewportWidth } /> | ||
<div className="block-editor-inserter__patterns-item-title"> | ||
{ pattern.title } | ||
</div> | ||
<VisuallyHidden id={ descriptionId }> |
There was a problem hiding this comment.
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.
There was a problem hiding this 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
sync with master
sync branch with master
How do you all feel about renaming "title" to label, matching register_block_style? Does it need to be a separate issue? |
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
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. |
How can we move this PR forward to include in 5.5 |
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? |
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. |
So to summarize the discussion during the accessibility teams meeting on friday: #23608 needs to be merged first so that the list of patterns is up to date. |
sync with master
trying to solve merge conflicts with the inserter updates
sync with master
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.
@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; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure where to upload it :) https://core.trac.wordpress.org/attachment/ticket/50550/50550-doing-it-wrong.patch
There was a problem hiding this 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
I merged too quickly without rewording the commit message. I guess it's fine for this time :). |
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: