Skip to content

Commit

Permalink
fix auto select override pre-selected value bug
Browse files Browse the repository at this point in the history
auto select should only apply to cases where select control doesn't have pre-selected value prop. If select control has pre-selected value (passed in from value prop), auto select first avaliable options should not apply.
  • Loading branch information
Grace Guo committed May 10, 2017
1 parent 874c12a commit aa21b65
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset/assets/javascripts/components/AsyncSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AsyncSelect extends React.PureComponent {
$.get(this.props.dataEndpoint, (data) => {
this.setState({ options: mutator ? mutator(data) : data, isLoading: false });

if (this.props.autoSelect && this.state.options.length) {
if (!this.props.value && this.props.autoSelect && this.state.options.length) {
this.onChange(this.state.options[0]);
}
})
Expand Down
12 changes: 12 additions & 0 deletions superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,17 @@ describe('AsyncSelect', () => {
expect(spy.callCount).to.equal(1);
expect(spy.calledWith(wrapper.instance().state.options[0])).to.equal(true);
});
it('should not auto select when value prop is set', () => {
const wrapper = mount(
<AsyncSelect {...mockedProps} value={2} autoSelect />,
);
const spy = sinon.spy(wrapper.instance(), 'onChange');

server.respond();

expect(spy.callCount).to.equal(0);
expect(wrapper.find(Select)).to.have.length(1);
expect(wrapper.find('.Select-value-label').children().first().text()).to.equal('another');
});
});
});

0 comments on commit aa21b65

Please sign in to comment.