-
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
Global Styles: Fix incorrect usage of ItemGroup in the Background image panel #68631
base: trunk
Are you sure you want to change the base?
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Hey @afercia, Whenever you have a moment, could you please review my PR? It addresses another instance of incorrect usage of the ItemGroup component in the Background Image panel. I’d really appreciate your feedback! |
@@ -125,7 +125,12 @@ function InspectorImagePreviewItem( { | |||
} | |||
}, [ toggleProps?.isOpen, onToggleCallback ] ); | |||
return ( | |||
<ItemGroup as={ as } className={ className } { ...toggleProps }> | |||
<ItemGroup | |||
role="none" |
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.
When the background image is set, ItemGroup is rendered as a button element. The role=none would override the native button role, which isn't okay.
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.
Maybe we can solve this with imgUrl ? "none" : "button"
. I'll try it out and update you.
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.
Or maybe based on the as
prop. However, this would be just a temporary workaround.
This component is still used incorrectly and against its documentation. We can implement a temporary fix but the long term goal is to not allow this kind of incorrect usage.
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.
@im3dabasia thanks for your PR. As mentioned in #67425 (comment) when the background image is set, this ItemGroup becomes a button element. Setting role=none
on the button would override the native button role and assistive technology would not communicate this as a button.
One option could be setting the role conditionally but it wouldn't be great having a button element with role=button.
I'd rather remove the ItemGroup entirely and explore a design change.
Thank you for your feedback @afercia . I agree that this is happening, but the button has ![]() As a temporary fix, I’d like to propose two possible solutions. Let me know which one you think works best:
<ItemGroup
role={ as === 'span' ? 'none' : 'button' }
as={as}
className={className}
{...toggleProps}
/> This would add role="none" by default when a span is rendered and otherwise apply role="button".
<ItemGroup
{...(as === 'span' ? { role: 'none' } : {})}
as={as}
className={className}
{...toggleProps}
/> This approach adds the role prop only when a span is rendered; otherwise, it allows the default behavior to prevail (i.e., a button with role="list"). Personally, I believe the first approach is better as it improves accessibility overall for this issue. Looking forward to here your thoughts @afercia |
We should avoid that so the first approach is better. However, this can only be acceptable as a temporary solution. |
Part of: #67425
What?
Revised
<ItemGroup>
to userole="none"
and prevent it from rendering an unnecessaryrole="list"
when it is not semantically required.Why?
Avoids adding unwanted list roles where a semantic list is not necessary, ensuring accessibility standards are maintained without enforcing unnecessary constraints.
How?
Updated
<ItemGroup>
to includerole="none"
and an optional as prop for flexibility. By defaultItemGroup
renders a as a list which was generating the wrong markup. Which is not good for accessibilityTesting Instructions
role="list"
when unnecessary.|