Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(checkbox): pass disabled prop to input #2800

Merged
merged 3 commits into from
May 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 18 additions & 30 deletions src/modules/Checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ export default class Checkbox extends Component {
fitted: PropTypes.bool,

/** A unique identifier. */
id: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

/** Whether or not checkbox is indeterminate. */
indeterminate: PropTypes.bool,
Expand Down Expand Up @@ -86,50 +83,32 @@ export default class Checkbox extends Component {
onMouseDown: PropTypes.func,

/** Format as a radio element. This means it is an exclusive option. */
radio: customPropTypes.every([
PropTypes.bool,
customPropTypes.disallow(['slider', 'toggle']),
]),
radio: customPropTypes.every([PropTypes.bool, customPropTypes.disallow(['slider', 'toggle'])]),

/** A checkbox can be read-only and unable to change states. */
readOnly: PropTypes.bool,

/** Format to emphasize the current selection state. */
slider: customPropTypes.every([
PropTypes.bool,
customPropTypes.disallow(['radio', 'toggle']),
]),
slider: customPropTypes.every([PropTypes.bool, customPropTypes.disallow(['radio', 'toggle'])]),

/** A checkbox can receive focus. */
tabIndex: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
tabIndex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

/** Format to show an on or off choice. */
toggle: customPropTypes.every([
PropTypes.bool,
customPropTypes.disallow(['radio', 'slider']),
]),
toggle: customPropTypes.every([PropTypes.bool, customPropTypes.disallow(['radio', 'slider'])]),

/** HTML input type, either checkbox or radio. */
type: PropTypes.oneOf(['checkbox', 'radio']),

/** The HTML input value. */
value: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
}

static defaultProps = {
type: 'checkbox',
}

static autoControlledProps = [
'checked',
'indeterminate',
]
static autoControlledProps = ['checked', 'indeterminate']

static _meta = {
name: 'Checkbox',
Expand Down Expand Up @@ -178,7 +157,11 @@ export default class Checkbox extends Component {

if (!this.canToggle()) return

_.invoke(this.props, 'onClick', e, { ...this.props, checked: !checked, indeterminate: !!indeterminate })
_.invoke(this.props, 'onClick', e, {
...this.props,
checked: !checked,
indeterminate: !!indeterminate,
})
_.invoke(this.props, 'onChange', e, { ...this.props, checked: !checked, indeterminate: false })

this.trySetState({ checked: !checked, indeterminate: false })
Expand All @@ -188,7 +171,11 @@ export default class Checkbox extends Component {
debug('handleMouseDown()')
const { checked, indeterminate } = this.state

_.invoke(this.props, 'onMouseDown', e, { ...this.props, checked: !!checked, indeterminate: !!indeterminate })
_.invoke(this.props, 'onMouseDown', e, {
...this.props,
checked: !!checked,
indeterminate: !!indeterminate,
})
_.invoke(this.inputRef, 'focus')

e.preventDefault()
Expand Down Expand Up @@ -250,6 +237,7 @@ export default class Checkbox extends Component {
{...htmlInputProps}
checked={checked}
className='hidden'
disabled={disabled}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the actual change, passing disabled attribute to the input if set as a prop to Checkbox

id={id}
name={name}
onClick={this.handleInputClick}
Expand Down