-
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
ItemGroup can be misused and render unsemantic not accessible markup #67425
Comments
Cc @WordPress/gutenberg-components |
One ore example if incorrect usage is the Image duotone filter control in the settings panel, where the gutenberg/packages/block-editor/src/components/global-styles/filters-panel.js Lines 191 to 201 in 8d343d1
Again, in terms of equivalent HTML, this is the equivalent of an unordered list that contains a button:
|
Noting that One way to fix the semantics could be to pass a prop |
Related: #64445 (We should keep these problems in mind when overhauling the component) |
One more example: The 'Add background image' in the global styles > Background: When an image is not set yet:
When an image is set:
Again, this appears one more case where ItemGroup is only used for visual purposes, to draw a gray border around other elements. No care at all has been taken into looking at the actually rendered markup and semantics. |
Description
<ItemGroup>
is supposed to 'display a list ofItem
s grouped and styled together'.The items are supposed to be visually and semantically grouped because the
<ItemGroup>
renders adiv
element with an ARIArole=list'. This is basically equivalent to an
element. As such, it is supposed to only contain
sub-components that render a
divelement with
role=listitem. This is basically equivalent to
As such,
<ItemGroup>
is the ARIA equivalent of an unordered list with list items.The documentation clearly states that ItemGroup should be used in combination with the Item sub-component. The documentation example is pretty clear as well.
However, in practice, ItemGroup accepts any children. There are several examples in the codebase where children other than
<Item>
are used within an<ItemGroup>
. This is semantically incorrect and not accessible. It's basically the equivalent of an<ul>
element that contains elements other than<li>
elements.Unfortunately, contributors to this project seem to not read the documentation and misuse this component only to get the 'visual aspect' of the
<ItemGroup>
not realizing they're going to render unsemantic and not accessible markup.On the other hand, the
<ItemGroup>
component doesn't enforce its children to be<Item>
sub-components. I would argue that it shouldm given its intended usage and its documentation.One example of this misuse is in the block bindings UI:
gutenberg/packages/block-editor/src/hooks/block-bindings.js
Lines 303 to 309 in 9ec5998
where the text highlighted in the screenshot is a
<span>
element inside a<div>
element withrole=list
. The equivalent in HTML would be something like the following:For the case in the screenshot above, that text should not use an
<ItemGroup>
in the first place. There are other usage cases in the editor that need to be investigated though.Still, this component is intended and documented to render a semantic list, while in practice it allows to be misused.
About the parent where
<ItemGroup>
is used intoSimilar concerns raise when the
<ItemGroup>
is used within elements that can't contain a list.Again, the
<ItemGroup>
is the equivalent of an<ul>
unordered list. For example, an<ul>
can't be used within a<button>
element (or any element with role=button). If that was a HTML<ul>
, it would be invalid HTML. Even if it's adiv
withrole=list
it's still semantically invalid.One example of this is the 'Add background image' control in the global Styles > Background:
In this case, there is a
<button>
element rendered byDropdown
, that contains an InspectorImagePreviewItem component which is an<ItemGroup>
that contains span elements. In terms of equivalent HTML this would be:Step-by-step reproduction instructions
role="list"
which in turns contains only<span>
elements.Screenshots, screen recording, code snippet
No response
Environment info
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
The text was updated successfully, but these errors were encountered: