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: Replace the AM/PM toggle ButtonGroup with ToggleGroupControl. #61562

Open
wants to merge 12 commits into
base: trunk
Choose a base branch
from

Conversation

patil-vipul
Copy link

@patil-vipul patil-vipul commented May 10, 2024

What?

Fixes #61163

Why?

When the is12Hour={true} setting is enabled, the AM/PM toggle relies solely on visual cues to convey its state, which presents a challenge for screen readers. This design overlooks accessibility needs, potentially creating barriers for users who rely on such assistive technologies.

How?

The previous ButtonGroup for toggling between AM/PM is replaced with ToggleGroupControl for better accessibility.

Testing Instructions

  • Create a new post and add the Date block.
  • Make sure your site is configured for 12 Hrs Time Format from the Settings >> General
  • Now edit the time on the date block using the "Edit" option (pencil icon) in the Block Controls Toolbar.
  • Test using the screen reader to read aloud the intended use of ToggleGroupControl.

Testing Instructions for Keyboard

  • Create a new post and add the Date block.
  • Make sure your site is configured for 12 Hrs Time Format from the Settings >> General
  • Now edit the time on the date block using the "Edit" option (pencil icon) in the Block Controls Toolbar.
  • Navigate to AM/PM selector using Tab key.
  • Once on AM/PM selector you can toggle between the two states using arrow keys.
  • To select the highlighted option press Spacebar.

Screenshots or screencast

Screenshot 2024-05-10 at 12 50 35 PM

The previous ButtonGroup for toggling between AM/PM is replaced with ToggleGroupControl for better accessibility.
Copy link

github-actions bot commented May 10, 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: patil-vipul <vipulpatil@git.wordpress.org>
Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: jameskoster <jameskoster@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

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

Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @patil-vipul! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label May 10, 2024
@juanfra juanfra added [Type] Enhancement A suggestion for improvement. [Block] Query Loop Affects the Query Loop Block [Block] Post Template Affects the Post Template Block labels May 10, 2024
@mirka mirka requested a review from a team May 20, 2024 15:45
@mirka mirka added the [Package] Components /packages/components label May 20, 2024
Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Great work here, thank you for the contribution!

am === 'AM' ? 'primary' : 'secondary'
}
__next40pxDefaultSize
aria-label="AM"
onClick={ buildAmPmChangeCallback( 'AM' ) }
Copy link
Member

Choose a reason for hiding this comment

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

Instead of handling changes on the click handlers for each option, we want it to be handled in the onChange of the ToggleGroupControl component itself. You can observe the difference when you try to change the value using keyboard arrow keys, rather than clicking.

am === 'AM' ? 'primary' : 'secondary'
}
__next40pxDefaultSize
aria-label="AM"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
aria-label="AM"

If the aria-label is the same as the label, we only need the label.

@@ -165,7 +165,7 @@ describe( 'TimePicker', () => {
/>
);

const pmButton = screen.getByText( 'PM' );
const pmButton = screen.getByLabelText( 'PM', { selector: 'button' } );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const pmButton = screen.getByLabelText( 'PM', { selector: 'button' } );
const pmButton = screen.getByRole( 'radio', { name: 'PM' } );

This would be the query we want to assert the correct accessibility semantics (same with the other instances).

Comment on lines 285 to 287
* This is not ideal, but best of we can do for now until we refactor
* AM/PM into accessible elements, like radio buttons.
*/
Copy link
Member

Choose a reason for hiding this comment

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

I believe we can remove this comment now?

@@ -2,6 +2,10 @@

## Unreleased

### Internal

- Replaced `ButtonGroup` with `ToggleGroupControl` component for "AM/PM" selector in DateTime component ([#61562](https://github.com/WordPress/gutenberg/pull/61562)).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- Replaced `ButtonGroup` with `ToggleGroupControl` component for "AM/PM" selector in DateTime component ([#61562](https://github.com/WordPress/gutenberg/pull/61562)).
- `DateTimePicker`: Replaced `ButtonGroup` with `ToggleGroupControl` component for "AM/PM" selector ([#61562](https://github.com/WordPress/gutenberg/pull/61562)).

Just a small tweak for easier scanning. Also, I think we can classify this as an Enhancement? Or maybe even a Bug Fix, since this fixes an accessibility bug. No strong opinion though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Template Affects the Post Template Block [Block] Query Loop Affects the Query Loop Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Components /packages/components [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DateTimePicker: AM/PM switcher is not screen reader accessible
3 participants