[RadioButtonGroup] onChange v.target.value != getSelectedValue()
I noticed something strange with RadioButtonGroup. If I fetch the value directly from the event emitted by onChange it's not the same as when I get the value from a ref.getSelectedValue()
handleRadio(v){
debug('radio change:', v.target.value, this.refs.radio.getSelectedValue());
}
Clicking a few time back and forth between two values: none all all none none all all none
and then clicking the same button a second time: none none
So v.target.value is always one click behind in updating its value
Loving the new radio buttons by the way! :)
Just hit myself on the same thing again, this time with a 0.13 approach. If this isn't a bug it's at least confusing ;)
The component below will print different values for _onChange. The 'value' is one selection behind on 'selected'.
export default class Question extends React.Component {
_onChange(e, selected){
let value = this._radio.getSelectedValue();
console.log('selected', value, selected);
}
render() {
const answers = this.props.answers.map((answer, index) => {
return (<mui.RadioButton
key={index}
value={answer}
label={answer} />);
});
return (
<div className='Question'>
<h2>{this.props.question}</h2>
<mui.RadioButtonGroup
ref={(c) => this._radio = c}
name="answers"
className="Question-answers"
onChange={this._onChange.bind(this)}>
{answers}
</mui.RadioButtonGroup>
</div>
);
}
};
@0x80 Sorry for getting back to you so late. This is definitely a bug! I believe it has to with React's setState being an asynchrounous function. One solution would be to wrap a timing event function over the onChange callback prop. However this hasn't been tested yet. Hopefully we can fix this quickly!
No problem, I'll keep it in mind. Thanks!
Also seems to affect Dropdown - sometime you get the change, sometimes not.
@mbrookes : Is it still an issue? Since you investigated something similar I need your opinion on this before closing.
No idea, sorry, but as there have been no other comments in 6 months I think it's safe to close.
This bug still exists in 0.16.7, a simple delay can be used as a temporary workaround :
<RadioButtonGroup name='type' onChange={this.handleRadioChange}> // ...
and :
handleRadioChange (e) {
e.persist();
setTimeout(() => {
this.setState({[e.target.name]: e.target.value})
}, 100)
}