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 aria-checked attribute not set for plugin settings buttons in Options dropdown #65667

Merged

Conversation

manzoorwanijk
Copy link
Contributor

What?

It fixes the a11y issue with plugin buttons in the options menu in the post editor where there is no indication of whether the plugin sidebar is already open or not.

Why?

Fixes #65666

How?

It updates ComplementaryAreaToggle to pass aria-checked if the role is set to menuitemcheckbox or menuitemradio

Testing Instructions

  • Install a plugin that adds a plugin menu/sidebar, e.g. Jetpack
  • Click on the options menu (3 dots)
  • Inspect the plugin settings button
  • Confirm that aria-checked attribute is set correctly

Testing Instructions for Keyboard

Screenshots or screencast

image

Copy link

github-actions bot commented Sep 26, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines 38 to 44
// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked
aria-checked={
props.role === 'menuitemcheckbox' ||
props.role === 'menuitemradio'
? isSelected
: undefined
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same approach used in

// Make sure aria-checked matches spec https://www.w3.org/TR/wai-aria-1.1/#aria-checked
aria-checked={
role === 'menuitemcheckbox' || role === 'menuitemradio'
? isSelected
: undefined
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this component is more generic than MenuItem, should we check for all of the roles are compatible with aria-checked ? Ie. checkbox, option, radio, switch, menuitemcheckbox, menuitemradio, treeitem ? (source)

Copy link
Member

Choose a reason for hiding this comment

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

I think the component rendered by plugins will always be MenuItem. See:

const PluginsMenuItem = ( {
// Menu item is marked with unstable prop for backward compatibility.
// They are removed so they don't leak to DOM elements.
// @see https://github.com/WordPress/gutenberg/issues/14457
__unstableExplicitMenuItem,
__unstableTarget,
...restProps
} ) => <MenuItem { ...restProps } />;
export default function ComplementaryAreaMoreMenuItem( {
scope,
target,
__unstableExplicitMenuItem,
...props
} ) {
return (
<ComplementaryAreaToggle
as={ ( toggleProps ) => {
return (
<ActionItem
__unstableExplicitMenuItem={
__unstableExplicitMenuItem
}
__unstableTarget={ `${ scope }/${ target }` }
as={ PluginsMenuItem }
name={ `${ scope }/plugin-more-menu` }
{ ...toggleProps }
/>
);
} }
role="menuitemcheckbox"
selectedIcon={ check }
name={ target }
scope={ scope }
{ ...props }
/>
);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the component rendered by plugins will always be MenuItem

That's true, but <ComplementaryAreaToggle /> is a generic component that technically can be rendered as anything, and therefore I don't think that checking for more roles can do any harm in this case

@manzoorwanijk
Copy link
Contributor Author

I wanted to add unit tests for that case but the component doesn't seem to have any tests at all.

We can cover that case when we add tests to this component.

@Mamaduka Mamaduka added [Type] Bug An existing feature does not function as intended General Interface Parts of the UI which don't fall neatly under other labels. labels Sep 26, 2024
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Makes sense. Thank you, @manzoorwanijk!

@Mamaduka Mamaduka added the props-bot Adding this label triggers the Props Bot workflow for a PR. label Sep 26, 2024
@github-actions github-actions bot removed the props-bot Adding this label triggers the Props Bot workflow for a PR. label Sep 26, 2024
@ciampo ciampo added the [Package] Interface /packages/interface label Sep 26, 2024
Copy link
Contributor

@ciampo ciampo left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@Mamaduka Mamaduka merged commit 427a8d0 into WordPress:trunk Sep 26, 2024
63 checks passed
@github-actions github-actions bot added this to the Gutenberg 19.4 milestone Sep 26, 2024
@manzoorwanijk manzoorwanijk deleted the fix/plugin-settings-button-aria-checked branch September 26, 2024 08:45
@sirreal sirreal added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Oct 8, 2024
@sirreal
Copy link
Member

sirreal commented Oct 8, 2024

Hmm… the flow to cherry-pick this failed:

https://github.com/WordPress/gutenberg/actions/runs/11232232902/job/31223400904

cbravobernal pushed a commit that referenced this pull request Oct 8, 2024
…ions dropdown (#65667)


Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
kevin940726 pushed a commit that referenced this pull request Oct 8, 2024
…ions dropdown (#65667)


Co-authored-by: manzoorwanijk <manzoorwanijk@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: ciampo <mciampini@git.wordpress.org>
@cbravobernal
Copy link
Contributor

cbravobernal commented Oct 8, 2024

I just cherry-picked this PR to the wp/6.7 branch to get it included in the next release: 381ada5

@cbravobernal cbravobernal added Backported to WP Core Pull request that has been successfully merged into WP Core and removed Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backported to WP Core Pull request that has been successfully merged into WP Core General Interface Parts of the UI which don't fall neatly under other labels. [Package] Interface /packages/interface [Type] Bug An existing feature does not function as intended
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Bug: aria-checked is not set on the Plugin settings buttons in Options menu
5 participants