-
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
PaletteEdit: Fix palette item accessibility #58214
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
* External dependencies | ||
*/ | ||
import styled from '@emotion/styled'; | ||
import { css } from '@emotion/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -10,20 +11,22 @@ import Button from '../button'; | |
import { Heading } from '../heading'; | ||
import { HStack } from '../h-stack'; | ||
import { space } from '../utils/space'; | ||
import { COLORS, CONFIG } from '../utils'; | ||
import { COLORS, CONFIG, font } from '../utils'; | ||
import { View } from '../view'; | ||
import InputControl from '../input-control'; | ||
import { | ||
Container as InputControlContainer, | ||
Input, | ||
BackdropUI as InputBackdropUI, | ||
} from '../input-control/styles/input-control-styles'; | ||
import CircularOptionPicker from '../circular-option-picker'; | ||
import ColorIndicator from '../color-indicator'; | ||
|
||
export const IndicatorStyled = styled( CircularOptionPicker.Option )` | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Changed this from |
||
&& { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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). |
||
flex-shrink: 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevents the indicator from shrinking when the color name is too long. |
||
width: ${ space( 6 ) }; | ||
height: ${ space( 6 ) }; | ||
} | ||
`; | ||
|
||
export const NameInputControl = styled( InputControl )` | ||
|
@@ -40,20 +43,66 @@ export const NameInputControl = styled( InputControl )` | |
} | ||
`; | ||
|
||
const buttonStyleReset = ( { | ||
as, | ||
}: { | ||
as: React.ComponentProps< typeof View >[ 'as' ]; | ||
} ) => { | ||
if ( as === 'button' ) { | ||
return css` | ||
display: flex; | ||
align-items: center; | ||
width: 100%; | ||
appearance: none; | ||
background: transparent; | ||
border: none; | ||
border-radius: 0; | ||
padding: 0; | ||
cursor: pointer; | ||
|
||
&:hover { | ||
color: ${ COLORS.theme.accent }; | ||
} | ||
`; | ||
} | ||
return null; | ||
}; | ||
|
||
export const PaletteItem = styled( View )` | ||
${ buttonStyleReset } | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. Reworked this part because |
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. This addresses #49041. |
||
|
||
&:focus-visible { | ||
border-color: transparent; | ||
box-shadow: 0 0 0 var( --wp-admin-border-width-focus ) | ||
var( | ||
--wp-components-color-accent, | ||
var( --wp-admin-theme-color, ${ COLORS.theme.accent } ) | ||
); | ||
// Windows high contrast mode. | ||
outline: 2px solid transparent; | ||
outline-offset: 0; | ||
} | ||
|
||
border-top-left-radius: ${ CONFIG.controlBorderRadius }; | ||
border-top-right-radius: ${ CONFIG.controlBorderRadius }; | ||
|
||
& + & { | ||
border-top-left-radius: 0; | ||
border-top-right-radius: 0; | ||
} | ||
&:last-of-type { | ||
|
||
&:last-child { | ||
border-bottom-left-radius: ${ CONFIG.controlBorderRadius }; | ||
border-bottom-right-radius: ${ CONFIG.controlBorderRadius }; | ||
border-bottom-color: ${ CONFIG.surfaceBorderColor }; | ||
} | ||
|
||
&.is-selected + & { | ||
border-top-color: transparent; | ||
} | ||
|
@@ -68,9 +117,6 @@ export const NameContainer = styled.div` | |
margin-right: ${ space( 2 ) }; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
${ PaletteItem }:hover & { | ||
color: ${ COLORS.theme.accent }; | ||
} | ||
`; | ||
|
||
export const PaletteHeading = styled( Heading )` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. The faux button is now properly accessible 🎉 |
||
await click( | ||
screen.getByRole( 'button', { | ||
name: 'Remove color', | ||
|
@@ -328,7 +328,7 @@ describe( 'PaletteEdit', () => { | |
name: 'Show details', | ||
} ) | ||
); | ||
await click( screen.getByText( 'Primary' ) ); | ||
await click( screen.getByRole( 'button', { name: 'Edit: Primary' } ) ); | ||
const nameInput = screen.getByRole( 'textbox', { | ||
name: 'Color name', | ||
} ); | ||
|
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.