Skip to content

Commit

Permalink
fix: should trigger onChange if click on options of multiple cascader…
Browse files Browse the repository at this point in the history
… with searchValue (#235)

* fix: should trigger onChange if click on options of multiple cascader with searchValue

* chore: update comment

* test: cover mousedown
  • Loading branch information
MadCcc authored Jan 13, 2022
1 parent b6dbf64 commit 9f9fc20
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, re

// =========================== Select ===========================
const onInternalSelect = useRefFunc((valuePath: SingleValueType) => {
setSearchValue('');
if (!multiple) {
triggerChange(valuePath);
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/OptionList/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ export default function Column({
triggerOpenPath();
}
}}
onMouseDown={e => {
// Prevent selector from blurring
e.preventDefault();
}}
>
{multiple && (
<Checkbox
Expand Down
11 changes: 11 additions & 0 deletions tests/search.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,15 @@ describe('Cascader.Search', () => {

errorSpy.mockRestore();
});

it('onChange should be triggered when click option with multiple', () => {
const onChange = jest.fn();
const wrapper = mount(
<Cascader checkable options={options} changeOnSelect onChange={onChange} showSearch />,
);
doSearch(wrapper, 'toy');
wrapper.find('.rc-cascader-menu-item').first().simulate('click');
wrapper.find('.rc-cascader-menu-item').first().simulate('mousedown');
expect(onChange).toHaveBeenCalledWith([['bamboo', 'little', 'fish']], expect.anything());
});
});

1 comment on commit 9f9fc20

@vercel
Copy link

@vercel vercel bot commented on 9f9fc20 Jan 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.