-
Notifications
You must be signed in to change notification settings - Fork 3
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
Repair Radio Checking onChange #15
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { PureComponent } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { connectTheme } from '../../../utils'; | ||
|
||
class Radio extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.state = { checked: 0 }; | ||
this.handleChecked = this.handleChecked.bind(this); | ||
} | ||
|
||
handleChecked(i) { | ||
this.setState({ checked: i }); | ||
} | ||
|
||
static get propTypes() { | ||
return { | ||
children: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
name: PropTypes.string.isRequired, | ||
onChange: PropTypes.func, | ||
placeholder: PropTypes.string, | ||
style: PropTypes.object, | ||
theme: PropTypes.object, | ||
type: PropTypes.string, | ||
value: PropTypes.string, | ||
}; | ||
} | ||
|
||
static get defaultProps() { | ||
return { | ||
onChange: this.handleChange, | ||
type: 'text', | ||
}; | ||
} | ||
|
||
render() { | ||
const { | ||
children, | ||
className, | ||
name, | ||
onChange, | ||
placeholder, | ||
style, | ||
theme, | ||
type, | ||
value, | ||
...otherProps | ||
} = this.props; | ||
|
||
return children.map((option, idx) => ( | ||
<div key={option} className={className}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having everything set to An ideal for this would be something like what semantic-ui does (http://react.semantic-ui.com/addons/radio/#types-radio-group). Unfortunately we don't have anything like Form.Field right now though... |
||
<label className={`form-label ${theme.input.capitalize}`}> | ||
<input | ||
checked={idx === this.state.checked} | ||
className={theme.input[type]} | ||
name={name} | ||
onChange={e => { | ||
this.handleChecked(idx); | ||
onChange(e); | ||
}} | ||
placeholder={placeholder} | ||
style={style} | ||
type={type} | ||
value={option} | ||
{...otherProps} | ||
/> | ||
{option} | ||
</label> | ||
</div> | ||
)); | ||
} | ||
} | ||
|
||
export default connectTheme(Radio); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I like this a lot. Also adds a lot more flexibility for more custom input types in the future 👍