Skip to content

Commit

Permalink
feat(Button): Prevent buttons from being disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanoglesby08 committed Aug 9, 2017
1 parent 31b4e53 commit 3024099
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/components/Button/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,29 @@ const getClassName = (variant, invert) => {
return styles[variant];
};

const preventDisabling = ({ disabled, ...props }) => {
if (disabled) {
warn('Button', 'Buttons are not able to be disabled.');
}

return props;
};

const safeRest = ({ style, className, ...props }) => props;

/**
*
* <span class="docs--badge green">new!</span>
*/
const Button = ({ type, variant, invert, children, ...rest }) => (
<button {...safeRest(rest)} type={type} className={getClassName(variant, invert)}>
{children}
</button>
);
const Button = ({ type, variant, invert, children, ...rest }) => {
const restNoDisabled = preventDisabling(rest);

return (
<button {...safeRest(restNoDisabled)} type={type} className={getClassName(variant, invert)}>
{children}
</button>
);
};

Button.propTypes = {
/**
Expand Down
4 changes: 4 additions & 0 deletions src/components/Button/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ const Hero = require('./__docs__/Hero').default;
<Button variant="outlined" invert>Go back</Button>
</Hero>
```

## Disabling buttons

We prefer buttons to always be interactive, so there is no need to disable it.
7 changes: 7 additions & 0 deletions src/components/Button/__tests__/Button.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ describe('Button', () => {
expect(warn).toHaveBeenCalled();
});

it('can not be disabled', () => {
const button = doShallow({ disabled: true });

expect(button).not.toHaveProp('disabled');
expect(warn).toHaveBeenCalled();
});

it('passes additional attributes to button element', () => {
const button = doShallow({ id: 'the-button', tabindex: 1 });

Expand Down

0 comments on commit 3024099

Please sign in to comment.