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

Dropdown selected option not updated after value property changes #103

Closed
leandrohsilveira opened this issue Sep 19, 2017 · 2 comments
Closed
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@leandrohsilveira
Copy link

If the Dropdown component prop "value" changes without an user selection event, a form reset event for example, the selected option will not visually update to match the new "value" property.

So, the controller value changed, but the visible component didn't.

class SampleForm extends React.Component {

    constructor(props) {
        super(props)
        this.state = {
            gender: props.gender || ''
        };
        this.handleFormReset = this.handleFormReset.bind(this);
        this.handleGenderChange = this.handleGenderChange.bind(this);
    }

    handleGenderChange(e) {
        this.setState({gender: e.value});
    }

    handleFormReset(e) {
        this.setState({gender: this.props.gender || ''});
    }

    render() {
        const genders = [
            {label: 'Male', value: 'M'},
            {label: 'Female', value: 'F'}
        ];
        return (
            <form onSubmit={() => this.props.onSubmit({gender: this.state.gender})} onReset={this.handleFormReset}>

                <Dropdown value={this.state.gender} options={genders} onChange={this.handleGenderChange} placeholder="Gender" />

                <button type="submit">Submit</button>
                <button type="reset">Reset</button>
            </form>
        )
    }

}

So, on form reset, the new value of state "gender" passed to Dropdown value property doesn't changes the Dropdown selected option.

@cagataycivici cagataycivici self-assigned this Sep 20, 2017
@cagataycivici cagataycivici added the Type: Bug Issue contains a defect related to a specific component. label Sep 20, 2017
@cagataycivici cagataycivici added this to the 1.0.1 milestone Sep 20, 2017
@cagataycivici
Copy link
Member

Replicated

@cagataycivici
Copy link
Member

I've reimplemented Dropdown and this issue is fixed along the way now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

No branches or pull requests

2 participants