Skip to content

Commit

Permalink
fix(Select): text should updated with dataSource changed
Browse files Browse the repository at this point in the history
  • Loading branch information
bindoon committed Jan 23, 2019
1 parent cdf79ee commit 16588fe
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion scripts/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function run(port) {
});

const url = `http://${host}:${port}/${componentName}`;
logger.warn(`Start server, listen to ${url}.`);
logger.warn(`Start server, listen to ${url}`);

const server = new WebpackDevServer(compiler, {
disableHostCheck: true,
Expand Down
8 changes: 5 additions & 3 deletions src/select/select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ class Select extends Base {
if ('value' in nextProps) {
// under controll
this.valueDataSource = getValueDataSource(nextProps.value, this.valueDataSource.mapValueDS, this.dataStore.getMapDS());
} else if ('defaultValue' in nextProps && (nextProps.children !== this.props.children || nextProps.dataSource !== this.props.dataSource)) {
//has defaultValue and dataSource changed
} else if ('defaultValue' in nextProps &&
nextProps.defaultValue === this.valueDataSource.value &&
(nextProps.children !== this.props.children || nextProps.dataSource !== this.props.dataSource)) {
//has defaultValue and value not changed and dataSource changed
this.valueDataSource = getValueDataSource(nextProps.defaultValue, this.valueDataSource.mapValueDS, this.dataStore.getMapDS());
}

Expand Down Expand Up @@ -620,7 +622,7 @@ class Select extends Base {

// because of can not close Popup by click Input while hasSearch.
// so when Popup open and hasSearch, we should close Popup intentionally
this.state.visible && this.hasSearch() && this.setVisible(!this.state.visible);
this.state.visible && this.hasSearch() && this.setVisible(false);
}

handleClear = e => {
Expand Down
25 changes: 25 additions & 0 deletions test/select/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,31 @@ describe('Select', () => {
assert(wrapper.find('.next-select em').text() === 'TT2');
});

it('should change display text while choose item and change dataSource', () => {
const dataSource = ['abc', 'bbb'];
class App extends React.Component {
render() {
return (
<Select
defaultValue={'0'}
visible
dataSource={dataSource.map((i, idx) => {
return { value: idx, label: i };
})}
onChange={() => {
this.setState({
a: 1,
});
}}
/>
);
}
}
wrapper = mount(<App/>);
ReactTestUtils.Simulate.click(document.querySelectorAll('.next-menu-item')[1]);
assert(wrapper.find('span.next-select em').text() === 'bbb');
});

it('should support not string value', (done) => {
const dataSource = [{ label: 'xxx', value: 123 }, { label: 'empty', value: false }];
const onChange = (value) => {
Expand Down

0 comments on commit 16588fe

Please sign in to comment.