Skip to content

Commit

Permalink
Always render a <button disabled> when rendering disabled Buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
BPScott committed Jan 10, 2019
1 parent b798970 commit dccf9ec
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ function Button({

const type = submit ? 'submit' : 'button';

return url ? (
// UnstyledLinks cant be disabled so always render a button when disabled
return url && !isDisabled ? (
<UnstyledLink
id={id}
url={url}
Expand Down
12 changes: 6 additions & 6 deletions src/components/Button/tests/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,30 @@ describe('<Button />', () => {
});

describe('disabled', () => {
it('disables the <button> by adding the disabled attribute', () => {
it('disable without a url renders <button disabled>', () => {
const button = shallowWithAppProvider(<Button disabled />);
expect(button.find('button').prop('disabled')).toBeTruthy();
});

it('does not add the disabled attribute to the <a> as `<a disabled>` is invalid HTML', () => {
it('disable with a url renders <button disabled> (as <a disabled> is invalid HTML)>', () => {
const button = shallowWithAppProvider(
<Button disabled url="http://google.com" />,
);
expect(button.find(UnstyledLink).prop('disabled')).toBeFalsy();
expect(button.find('button').prop('disabled')).toBeTruthy();
});
});

describe('loading', () => {
it('disables the <button> by adding the disabled attribute', () => {
it('loading without a url renders <button disabled>', () => {
const button = shallowWithAppProvider(<Button loading />);
expect(button.find('button').prop('disabled')).toBe(true);
});

it('does not add the disabled attribute to the <a> as `<a disabled>` is invalid HTML', () => {
it('loading with a url renders <button disabled> (as <a disabled> is invalid HTML)', () => {
const button = shallowWithAppProvider(
<Button loading url="http://google.com" />,
);
expect(button.find(UnstyledLink).prop('disabled')).toBeFalsy();
expect(button.find('button').prop('disabled')).toBeTruthy();
});

it('renders a spinner into the button', () => {
Expand Down

0 comments on commit dccf9ec

Please sign in to comment.