Skip to content

Commit

Permalink
fix(Button): Add missing aria-label to buttons without icons (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
cogwirrel authored Sep 23, 2021
1 parent f591166 commit 68cd67e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/components/Button/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe('Button', () => {
expect(queryByRole('progressbar')).not.toBeInTheDocument();
});

it('renders with an aria-label', () => {
const props = { variant, label: 'some label' };
const { getByRole } = render(<Button {...props}>test</Button>);
expect(getByRole('button')).toHaveAttribute('aria-label', props.label);
});

describe('when loading', () => {
it('disables button and renders a loader without icon from props ', () => {
const props = { loading: true, variant, icon: 'add_plus' as ButtonIconType };
Expand Down
3 changes: 3 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const muiButtonProps = ({
href,
icon,
iconAlign,
label,
type = 'button',
size = 'medium',
}: Partial<ButtonProps>): MaterialButtonProps => {
Expand All @@ -116,6 +117,7 @@ const muiButtonProps = ({
onClick,
type,
size,
'aria-label': label,
...(icon && { [iconAlign === 'right' ? 'endIcon' : 'startIcon']: <ButtonIcon type={icon} /> }),
...(loading && { startIcon: <OffsetCircularProgress /> }),
...getVariantProps(),
Expand Down Expand Up @@ -163,6 +165,7 @@ const Button: FunctionComponent<ButtonProps> = ({
loading,
icon,
iconAlign,
label,
type,
size,
})}
Expand Down

0 comments on commit 68cd67e

Please sign in to comment.