Skip to content

Commit

Permalink
Merge ff66481 into d5ec884
Browse files Browse the repository at this point in the history
  • Loading branch information
gbk committed Mar 7, 2018
2 parents d5ec884 + ff66481 commit fa83abb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.4.6

* `FIXED` fix issue #10 add missing onSubmit handler

# 0.4.5

* `IMPROVE` fix issue #8 keep selection order.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uxcore-multi-select",
"version": "0.4.5",
"version": "0.4.6",
"description": "uxcore-multi-select component for uxcore.",
"repository": "https://github.com/uxcore/uxcore-multi-select.git",
"author": "peijie.dpj",
Expand Down Expand Up @@ -53,4 +53,4 @@
},
"contributors": [],
"license": "MIT"
}
}
11 changes: 11 additions & 0 deletions src/MultiSelect.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,20 @@ export default class MultiSelect extends Component {
};

handleOk = () => {
const { props, state } = this;
this.setState({
visible: false,
});

const lastLabels = [];
state.lastValues.forEach((value) => {
React.Children.forEach(props.children, (item) => {
if (value === item.props.value) {
lastLabels.push(item.props.text || item.props.value);
}
});
})
props.onSubmit(state.lastValues, lastLabels);
}

processLabel = (type) => {
Expand Down
11 changes: 8 additions & 3 deletions tests/MultiSelect.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ describe('MultiSelect', () => {
expect(instance.state().visible).to.be(false);
});

it('triggers handleChange correctly', () => {
it('triggers handleChange and handleOk correctly', () => {
const spy = sinon.spy();
instance = mount(
<MultiSelect onChange={spy} maxSelect={2}>
<Item value="1" />
<MultiSelect onChange={spy} maxSelect={2} onSubmit={spy}>
<Item value="1" text="text1" />
<Item value="2" />
<Item value="3" />
</MultiSelect>
Expand Down Expand Up @@ -114,6 +114,11 @@ describe('MultiSelect', () => {
checkBox3.simulate('change');
expect(spy.callCount).to.be(3);
expect(spy.args[2][0]).to.eql(['1', '2']);
spy.reset();
instance.instance().handleOk();
expect(spy.callCount).to.be(1);
expect(spy.args[0][0]).to.eql(['1', '2']);
expect(spy.args[0][1]).to.eql(['text1', '2']);
});

it('triggers handleSelectAll and handleClear correctly', () => {
Expand Down

0 comments on commit fa83abb

Please sign in to comment.