-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
PaletteEdit: Fix palette item accessibility #58214
Conversation
For better visual testing of PaletteItem borders
Size Change: +2.68 kB (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
@@ -56,6 +56,7 @@ Default.args = { | |||
colors: [ | |||
{ color: '#1a4548', name: 'Primary', slug: 'primary' }, | |||
{ color: '#0000ff', name: 'Secondary', slug: 'secondary' }, | |||
{ color: '#fb326b', name: 'Tertiary', slug: 'tertiary' }, |
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.
Increased this to three colors so we can better check the border radiuses in details view.
width: ${ space( 6 ) }; | ||
height: ${ space( 6 ) }; | ||
pointer-events: none; | ||
export const IndicatorStyled = styled( ColorIndicator )` |
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.
Changed this from CircularOptionPicker.Option
(which is a button) to a simple ColorIndicator
. This isn't supposed to be an independent button — the entire item row is a button with a single onClick handler.
pointer-events: none; | ||
export const IndicatorStyled = styled( ColorIndicator )` | ||
&& { | ||
flex-shrink: 0; |
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.
Prevents the indicator from shrinking when the color name is too long.
height: ${ space( 6 ) }; | ||
pointer-events: none; | ||
export const IndicatorStyled = styled( ColorIndicator )` | ||
&& { |
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.
Without this added specificity, the intended sizing (24px) was sometimes not being applied due to load order. This was one of the things causing style inconsistencies (#49041).
&:first-of-type { | ||
border-top-left-radius: ${ CONFIG.controlBorderRadius }; | ||
border-top-right-radius: ${ CONFIG.controlBorderRadius }; | ||
font-size: ${ font( 'default.fontSize' ) }; |
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.
This addresses #49041.
padding-block: 3px; | ||
padding-inline-start: ${ space( 3 ) }; | ||
border: 1px solid ${ CONFIG.surfaceBorderColor }; | ||
border-bottom-color: transparent; | ||
&:first-of-type { |
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.
Reworked this part because :first-of-type
will not work anymore with the button/div polymorphism, and Emotion doesn't want us to use :first-child
for SSR safety. (Apparently :last-child
is ok)
@@ -295,7 +295,7 @@ describe( 'PaletteEdit', () => { | |||
name: 'Show details', | |||
} ) | |||
); | |||
await click( screen.getByText( 'Primary' ) ); | |||
await click( screen.getByRole( 'button', { name: 'Edit: Primary' } ) ); |
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.
The faux button is now properly accessible 🎉
Flaky tests detected in b3c0d36. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7643570992
|
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.
Thank you for the PR! From what I've tested, I think it works as expected for both Global Styles and Storybook.
One thing I was concerned about is what to do with aria-label
when the color name is empty. Probably we shouldn't allow empty color names to be defined, but for example, would it make sense to read out the color code instead?
6817f2e721c9c7a2b8939a73c14099f1.mp4
Also, because the color indicator is no longer a button element, the round border no longer appears in Windows high contrast mode. I think we just need to apply border 1px solid transparent
to the color indicator.
Update: I've noticed that this indicator doesn't appear on other color panels either, so this may be outside the scope of this PR.
Thanks for the review @t-hamano!
Good call. I added some fallbacks in 3e560ed, which should be good to have in place regardless of how we enforce/validate the color naming in the future.
You're probably right, this needs to be addressed in the underlying component. Although, I'm actually not sure if a non-interactive color swatch needs a border in high contrast mode. |
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.
LGTM 👍
- When the color name is empty, the screen reader reads the actual color value
- The screen reader still reads the actual color value even if the color name contains only spaces
- I think the non-breaking space when the color name is empty also makes sense.
Follow-up to #57645 (comment)
Fixes #49041
What?
Fixes palette item accessibility in the details view of the PaletteEdit component.
Note
This doesn't fix the issue where focus gets stuck in the ColorPicker popover (#58188).
Why?
Only the swatch was a focusable button, and it was unlabeled.
Testing Instructions
There should be no changes in behavior when navigating by pointer.
Testing Instructions for Keyboard
Either in Storybook or the Editor (Global Styles ▸ Colors ▸ Palette):
Note
There is currently a style leak in the Editor that causes the palette item to have an unintentional background color when in editing mode.
Screenshots or screencast
Before
CleanShot.2024-01-25.at.02.00.05.mp4
After
CleanShot.2024-01-25.at.02.01.40.mp4