Skip to content

Commit

Permalink
Fix Button's disabled state when not loading (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Oct 14, 2021
1 parent d22a701 commit 9e5bfc1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/clever-carrots-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup/circuit-ui': patch
---

Fixed a bug in the Button component when it is disabled and not loading.
42 changes: 36 additions & 6 deletions packages/circuit-ui/components/Button/Button.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,42 @@ describe('Button', () => {
expect(props.onClick).toHaveBeenCalledTimes(1);
});

/**
* Should accept a working ref for button
*/
it('should render as disabled', () => {
const props = { ...baseProps, disabled: true };
const { getByRole } = renderButton(render, props);

const button = getByRole('button');

expect(button).toBeDisabled();
});

it('should render as disabled when loading', () => {
const props = {
...baseProps,
isLoading: true,
loadingLabel: 'Loading',
};
const { getByRole } = renderButton(render, props);

const button = getByRole('button');

expect(button).toBeDisabled();
});

it('should render as disabled when not loading', () => {
const props = {
...baseProps,
disabled: true,
isLoading: false,
loadingLabel: 'Loading',
};
const { getByRole } = renderButton(render, props);

const button = getByRole('button');

expect(button).toBeDisabled();
});

it('should accept a working ref for a button', () => {
const tref = createRef<any>();
const { container } = render(
Expand All @@ -145,9 +178,6 @@ describe('Button', () => {
expect(tref.current).toBe(button);
});

/**
* Should accept a working ref for link
*/
it('should accept a working ref for a link', () => {
const tref = createRef<any>();
const { container } = render(
Expand Down
3 changes: 2 additions & 1 deletion packages/circuit-ui/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ export const Button = forwardRef(
(
{
children,
disabled,
isLoading,
loadingLabel,
icon: Icon,
Expand Down Expand Up @@ -372,10 +373,10 @@ export const Button = forwardRef(
<StyledButton
{...props}
{...(loadingLabel && {
'disabled': isLoading,
'aria-live': 'polite',
'aria-busy': isLoading,
})}
disabled={disabled || isLoading}
ref={ref}
as={props.href ? Link : 'button'}
onClick={handleClick}
Expand Down

1 comment on commit 9e5bfc1

@vercel
Copy link

@vercel vercel bot commented on 9e5bfc1 Oct 14, 2021

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.