-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
SelectField needs more methods #2504
Comments
@jgog these methods are imperative and make handling the flow of data really hard, that's why we prefer not to support them (directly) but the fact is, it's very easy to write a wrapper component to expose such methods. and of course, you'll need only one wrapper: class ImperativeWrapper extends React.Component {
constructor(props) {
super(props);
this.state = {value: props.defaultValue};
}
setValue = value => this.setState({value});
getValue = () => this.state.value;
clearValue = () => this.setState({value: this.props.defaultValue});
handle = value => this.setState({value});
render() {
const {Component, ...other} = this.props;
return <Component {...other} value={this.state.value} onChange={this.handle}/>;
}
} And you would use it like this: //...
getAllValues() {
// The imperative method...
const selectValue = this.refs['my-select-field'].getValue();
}
render() {
return (
<ImperativeWrapper
ref="my-select-field"
defaultValue={/*...*/}
items={/*...*/}
// And other SelectField props you want to pass down
Component={SelectField}/>
}
//... Although this might need a bit of tweaking to make SelectField work with it (and I apologize, I don't have the time to test it my self), but you get the point. We can provide such wrappers as helper components, but that will have to be decided on. @oliviertassinari Thoughts? |
@subjectix Thanks for the explanation, but I thought a |
Will be fixed by the |
Can we have
getValue
andsetValue
methods for SelectFields?I understand
SelectField
andDropDownMenu
are undergoing a lot of change recently but these methods will be a good-to-have.The text was updated successfully, but these errors were encountered: