Skip to content

Commit

Permalink
Make circular option picker get a group role and optional label when …
Browse files Browse the repository at this point in the history
…rendered as buttons.
  • Loading branch information
afercia committed Jan 14, 2025
1 parent b2f40e5 commit e1515e0
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 19 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/cover/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ function CoverEdit( {
onChange={ onSetOverlayColor }
clearable={ false }
asButtons
aria-label={ __( 'Background color' ) }
/>
</div>
</CoverPlaceholder>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function ButtonsCircularOptionPicker(
);

return (
<div { ...additionalProps } id={ baseId }>
<div { ...additionalProps } role="group" id={ baseId }>
<CircularOptionPickerContext.Provider value={ contextValue }>
{ options }
{ children }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ WithLoopingDisabled.parameters = {
docs: {
source: {
code: `<CircularOptionPicker
aria-label="${ WithLoopingDisabled.args[ 'aria-label' ] }"
'aria-label': 'Circular Option Picker',
loop={false}
options={<DefaultOptions />}
/>`,
Expand Down
22 changes: 11 additions & 11 deletions packages/components/src/circular-option-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ type CommonCircularOptionPickerProps = {
* The child elements.
*/
children?: ReactNode;
};
} & (
| {
'aria-label': string;
'aria-labelledby'?: never;
}
| {
'aria-label'?: never;
'aria-labelledby': string;
}
);

type WithBaseId = {
baseId: string;
Expand All @@ -59,16 +68,7 @@ type FullListboxCircularOptionPickerProps = CommonCircularOptionPickerProps & {
* @default true
*/
loop?: boolean;
} & (
| {
'aria-label': string;
'aria-labelledby'?: never;
}
| {
'aria-label'?: never;
'aria-labelledby': string;
}
);
};

export type ListboxCircularOptionPickerProps = WithBaseId &
Omit< FullListboxCircularOptionPickerProps, 'asButtons' >;
Expand Down
21 changes: 19 additions & 2 deletions packages/components/src/color-palette/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,27 @@ function UnforwardedColorPalette(
let metaProps:
| { asButtons: false; loop?: boolean; 'aria-label': string }
| { asButtons: false; loop?: boolean; 'aria-labelledby': string }
| { asButtons: true };
| { asButtons: true; 'aria-label': string }
| { asButtons: true; 'aria-labelledby': string };

if ( asButtons ) {
metaProps = { asButtons: true };
const _metaProps: { asButtons: true } = {
asButtons: true,
};

if ( ariaLabel ) {
metaProps = { ..._metaProps, 'aria-label': ariaLabel };
} else if ( ariaLabelledby ) {
metaProps = {
..._metaProps,
'aria-labelledby': ariaLabelledby,
};
} else {
metaProps = {
..._metaProps,
'aria-label': __( 'Custom color picker.' ),
};
}
} else {
const _metaProps: { asButtons: false; loop?: boolean } = {
asButtons: false,
Expand Down
21 changes: 19 additions & 2 deletions packages/components/src/duotone-picker/duotone-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,27 @@ function DuotonePicker( {
let metaProps:
| { asButtons: false; loop?: boolean; 'aria-label': string }
| { asButtons: false; loop?: boolean; 'aria-labelledby': string }
| { asButtons: true };
| { asButtons: true; 'aria-label': string }
| { asButtons: true; 'aria-labelledby': string };

if ( asButtons ) {
metaProps = { asButtons: true };
const _metaProps: { asButtons: true } = {
asButtons: true,
};

if ( ariaLabel ) {
metaProps = { ..._metaProps, 'aria-label': ariaLabel };
} else if ( ariaLabelledby ) {
metaProps = {
..._metaProps,
'aria-labelledby': ariaLabelledby,
};
} else {
metaProps = {
..._metaProps,
'aria-label': __( 'Custom color picker.' ),
};
}
} else {
const _metaProps: { asButtons: false; loop?: boolean } = {
asButtons: false,
Expand Down
21 changes: 19 additions & 2 deletions packages/components/src/gradient-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,27 @@ function Component( props: PickerProps< any > ) {
let metaProps:
| { asButtons: false; loop?: boolean; 'aria-label': string }
| { asButtons: false; loop?: boolean; 'aria-labelledby': string }
| { asButtons: true };
| { asButtons: true; 'aria-label': string }
| { asButtons: true; 'aria-labelledby': string };

if ( asButtons ) {
metaProps = { asButtons: true };
const _metaProps: { asButtons: true } = {
asButtons: true,
};

if ( ariaLabel ) {
metaProps = { ..._metaProps, 'aria-label': ariaLabel };
} else if ( ariaLabelledby ) {
metaProps = {
..._metaProps,
'aria-labelledby': ariaLabelledby,
};
} else {
metaProps = {
..._metaProps,
'aria-label': __( 'Custom color picker.' ),
};
}
} else {
const _metaProps: { asButtons: false; loop?: boolean } = {
asButtons: false,
Expand Down

0 comments on commit e1515e0

Please sign in to comment.