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
base: trunk
Are you sure you want to change the base?
FIX: Replace the AM/PM toggle ButtonGroup with ToggleGroupControl. #61562
Conversation
The previous ButtonGroup for toggling between AM/PM is replaced with ToggleGroupControl for better accessibility.
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. |
👋 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. |
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.
Great work here, thank you for the contribution!
am === 'AM' ? 'primary' : 'secondary' | ||
} | ||
__next40pxDefaultSize | ||
aria-label="AM" | ||
onClick={ buildAmPmChangeCallback( 'AM' ) } |
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.
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" |
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.
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' } ); |
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.
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).
* This is not ideal, but best of we can do for now until we refactor | ||
* AM/PM into accessible elements, like radio buttons. | ||
*/ |
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 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)). |
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.
- 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.
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
Testing Instructions for Keyboard
Tab
key.Spacebar
.Screenshots or screencast