Skip to content

Commit

Permalink
feat: add aria-label to action items
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 21, 2020
1 parent 71876ab commit 8b51ae1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The third-libraries used include in no particular order:
- [react-popper-tooltip](https://react-popper-tooltip.netlify.com) for popups and tooltips.
- [react-animate-height](https://muffinman.io/react-animate-height/) for collapsible components.
- [@theme-ui/presets](https://theme-ui.com/packages/presets/) for custom theming.
- [react-switch](https://github.com/markusenglund/react-switch) for toggle editor

<!-- END-PACKAGE-SECTION -->

Expand Down
51 changes: 31 additions & 20 deletions ui/components/src/ActionBar/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export interface ActionItem {
* optional order, if not provided will use the natural order of items from right to left
*/
order?: number;

/**
* optional label visible to screen readers for aria accessibility.
*/
'aria-label'?: string;
}

export interface ActionBarProps {
Expand Down Expand Up @@ -111,26 +116,32 @@ export const ActionBar: FunctionComponent<ActionBarProps> = ({
//@ts-ignore
return a.order - b.order;
})
.map(({ title, onClick, disabled }, index) => (
<Box
key={`${typeof title === 'string' ? title : 'item'}_${index}`}
sx={{
mt: 1,
mx: 1,
fontSize: 1,
a: ActionColors({ theme, disabled }),
button: ActionColors({ theme, disabled }),
}}
>
{typeof title === 'string' ? (
<Button onClick={onClick} disabled={disabled}>
{title}
</Button>
) : (
title
)}
</Box>
))}
.map(
({ title, onClick, disabled, 'aria-label': ariaLabel }, index) => (
<Box
key={`${typeof title === 'string' ? title : 'item'}_${index}`}
sx={{
mt: 1,
mx: 1,
fontSize: 1,
a: ActionColors({ theme, disabled }),
button: ActionColors({ theme, disabled }),
}}
>
{typeof title === 'string' ? (
<Button
onClick={onClick}
disabled={disabled}
aria-label={ariaLabel}
>
{title}
</Button>
) : (
title
)}
</Box>
),
)}
</Flex>
</Box>
);
Expand Down
7 changes: 6 additions & 1 deletion ui/components/src/Source/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export const Source: FC<SourceProps> = ({
};

const actionsItems = [
{ title: copied ? 'copied' : 'copy', onClick: onCopy },
{
title: copied ? 'copied' : 'copy',
onClick: onCopy,
id: 'copy',
'aria-label': 'copy the displayed source code',
},
...(Array.isArray(actions) ? [...actions] : []),
];

Expand Down

0 comments on commit 8b51ae1

Please sign in to comment.