Unverified Commit f705f6be authored by Kyle Keating's avatar Kyle Keating Committed by GitHub

Merge pull request #1760 from hypothesis/button-disabled

Add `disabled` prop to the Button component
parents a3356649 f39b0810
...@@ -19,6 +19,7 @@ import SvgIcon from './svg-icon'; ...@@ -19,6 +19,7 @@ import SvgIcon from './svg-icon';
export default function Button({ export default function Button({
buttonText = '', buttonText = '',
className = '', className = '',
disabled = false,
icon = '', icon = '',
isActive = false, isActive = false,
onClick = () => null, onClick = () => null,
...@@ -51,6 +52,7 @@ export default function Button({ ...@@ -51,6 +52,7 @@ export default function Button({
aria-pressed={isActive} aria-pressed={isActive}
title={title} title={title}
style={style} style={style}
disabled={disabled}
> >
{icon && <SvgIcon name={icon} className="button__icon" />} {icon && <SvgIcon name={icon} className="button__icon" />}
{buttonText} {buttonText}
...@@ -108,6 +110,9 @@ Button.propTypes = { ...@@ -108,6 +110,9 @@ Button.propTypes = {
/** callback for button clicks */ /** callback for button clicks */
onClick: propTypes.func, onClick: propTypes.func,
/** disables the button when true */
disabled: propTypes.bool,
/** optional inline styling */ /** optional inline styling */
style: propTypes.object, style: propTypes.object,
......
...@@ -91,6 +91,16 @@ describe('Button', () => { ...@@ -91,6 +91,16 @@ describe('Button', () => {
assert.isTrue(wrapper.find('button').hasClass('button--primary')); assert.isTrue(wrapper.find('button').hasClass('button--primary'));
}); });
it('disables the button when `disabled` prop is true', () => {
const wrapper = createComponent({ disabled: true });
assert.isTrue(wrapper.find('button[disabled=true]').exists());
});
it('shall not disable the button by default', () => {
const wrapper = createComponent();
assert.isTrue(wrapper.find('button[disabled=false]').exists());
});
it( it(
'should pass a11y checks', 'should pass a11y checks',
checkAccessibility({ checkAccessibility({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment