Skip to content

Commit

Permalink
click close do not trigger Trigger (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Apr 28, 2018
1 parent 3ce1332 commit d9b55e1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,17 @@ class Select extends Component {
}
}

removeSelected(selectedVal) {
removeSelected(selectedVal, e) {
const props = this.props;
if (props.disabled) {
return;
}

// Do not trigger Trigger popup
if (e && e.stopPropagation) {
e.stopPropagation();
}

this._cacheTreeNodesStates = 'no';
if (props.treeCheckable &&
(props.showCheckedStrategy === SHOW_ALL || props.showCheckedStrategy === SHOW_PARENT)
Expand Down Expand Up @@ -692,6 +698,7 @@ class Select extends Component {
});
}
}

this.fireChange(value, { triggerValue: selectedVal, clear: true });
}

Expand Down Expand Up @@ -842,7 +849,9 @@ class Select extends Component {
>
<span
className={`${prefixCls}-selection__choice__remove`}
onClick={this.removeSelected.bind(this, singleValue.value)}
onClick={(event) => {
this.removeSelected(singleValue.value, event);
}}
/>
<span className={`${prefixCls}-selection__choice__content`}>{content}</span>
</li>
Expand Down
11 changes: 11 additions & 0 deletions tests/Select.multiple.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,15 @@ describe('TreeSelect.multiple', () => {
select(wrapper, 0); // unselect
expect(wrapper.find('input').getDOMNode().value).toBe('');
});

it('do not open tree when close button click', () => {
const wrapper = mount(createSelect());
wrapper.find('.rc-tree-select-selection').simulate('click');
select(wrapper, 0);
select(wrapper, 1);
wrapper.setState({ open: false });
wrapper.find('.rc-tree-select-selection__choice__remove').at(0).simulate('click');
expect(wrapper.state('open')).toBe(false);
expect(wrapper.state('value')).toEqual([{ label: 'label1', value: '1' }]);
});
});

0 comments on commit d9b55e1

Please sign in to comment.