Skip to content

Commit

Permalink
adds missing aria-busy property on Button Component when the button i…
Browse files Browse the repository at this point in the history
…sLoading (#1475)

* solves #1474 Stringifying boolean and defaulting undefined on aria-busy value on Button Component

* adds changeset

* removes the usage of lodash isBoolean in favour of typeof

* replaces snapshot testing for aria-live and aria-busy with attribute checking

* updates changeset message and update type
  • Loading branch information
tareqlol authored Mar 11, 2022
1 parent 5a8e0fc commit 82112c1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-moles-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Fixed the conditional rendering of aria attributes in loading buttons.
22 changes: 22 additions & 0 deletions packages/circuit-ui/components/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,5 +206,27 @@ describe('Button', () => {
const actual = await axe(wrapper);
expect(actual).toHaveNoViolations();
});

it('should have aria-busy and aria-live for a loading button', () => {
const { getByRole } = renderButton(render, {
...baseProps,
isLoading: true,
loadingLabel: 'Loading...',
});
const button = getByRole('button');

expect(button).toHaveAttribute('aria-live', 'polite');
expect(button).toHaveAttribute('aria-busy', 'true');
});

it('should not have aria-busy and aria-live for a regular button', () => {
const { getByRole } = renderButton(render, {
...baseProps,
});
const button = getByRole('button');

expect(button).not.toHaveAttribute('aria-live');
expect(button).not.toHaveAttribute('aria-busy');
});
});
});
9 changes: 5 additions & 4 deletions packages/circuit-ui/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,11 @@ export const Button = forwardRef(
return (
<StyledButton
{...props}
{...(loadingLabel && {
'aria-live': 'polite',
'aria-busy': isLoading,
})}
{...(loadingLabel &&
typeof isLoading === 'boolean' && {
'aria-live': 'polite',
'aria-busy': isLoading,
})}
disabled={disabled || isLoading}
ref={ref}
as={props.href ? Link : 'button'}
Expand Down

1 comment on commit 82112c1

@vercel
Copy link

@vercel vercel bot commented on 82112c1 Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.