Skip to content

Commit 7f0167f

Browse files
authored
fix: changeOnSelect should not show children (#404)
1 parent 6bdeb06 commit 7f0167f

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ coverage
3636

3737
# dumi
3838
.dumi/tmp
39-
.dumi/tmp-production
39+
.dumi/tmp-production

src/hooks/useSearchOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default (
5353
fieldNames,
5454
),
5555
[SEARCH_MARK]: connectedPathOptions,
56+
[fieldNames.children]: undefined,
5657
});
5758
}
5859
}

tests/search.spec.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ describe('Cascader.Search', () => {
7474
});
7575

7676
it('changeOnSelect', () => {
77-
const wrapper = mount(<Cascader options={options} open showSearch changeOnSelect />);
77+
const onChange = jest.fn();
78+
const wrapper = mount(
79+
<Cascader options={options} onChange={onChange} open showSearch changeOnSelect />,
80+
);
7881

7982
// Leaf
8083
doSearch(wrapper, 'Label Little');
@@ -83,6 +86,14 @@ describe('Cascader.Search', () => {
8386
expect(itemList.at(0).text()).toEqual('Label Bamboo / Label Little');
8487
expect(itemList.at(1).text()).toEqual('Label Bamboo / Label Little / Toy Fish');
8588
expect(itemList.at(2).text()).toEqual('Label Bamboo / Label Little / Toy Cards');
89+
90+
// Should not expandable
91+
expect(wrapper.exists('.rc-cascader-menu-item-expand-icon')).toBeFalsy();
92+
93+
// Trigger onChange
94+
wrapper.find('input').simulate('keyDown', { which: KeyCode.DOWN });
95+
wrapper.find('input').simulate('keyDown', { which: KeyCode.ENTER });
96+
expect(onChange).toHaveBeenCalledWith(['bamboo', 'little'], expect.anything());
8697
});
8798

8899
it('sort', () => {

0 commit comments

Comments
 (0)