Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: autoClearSearchValue invalid #949

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Select.tsx
Expand Up @@ -544,7 +544,9 @@ const Select = React.forwardRef(
const newRawValues = Array.from(new Set<RawValueType>([...rawValues, formatted]));
triggerChange(newRawValues);
triggerSelect(formatted, true);
setSearchValue('');
if(autoClearSearchValue) {
Copy link
Member

Choose a reason for hiding this comment

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

我给这两个 case 打了断点,不会跑到这里。确认一下是否是搞错地方了?

Copy link
Member

Choose a reason for hiding this comment

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

断点显示是来自上方的重置,再看看?

截屏2023-06-12 14 01 19

setSearchValue('');
}
}

return;
Expand Down
36 changes: 36 additions & 0 deletions tests/Select.test.tsx
Expand Up @@ -2040,4 +2040,40 @@ describe('Select.Basic', () => {
const { container } = testingRender(<Select open direction="rtl" options={options} />);
expect(container.querySelector('.rc-virtual-list-rtl')).toBeTruthy();
});


it('autoClearSearchValue false', () => {
const wrapper = mount(
<Select
mode="tags"
options={[
{ label: 'bamboo', title: 'TitleBamboo', value: 'b' },
{ label: 'little', value: 'l' },
{ label: 'Rest', value: 'r' },
]}
/>,
);
wrapper.setProps({autoClearSearchValue:false})
wrapper.find('input').simulate('change', { target: { value: 'Two2' } });
selectItem(wrapper, );
expect(wrapper.find('input').prop('value')).toBe('Two2');
});

it('autoClearSearchValue true', () => {
const wrapper = mount(
<Select
mode="tags"
options={[
{ label: 'bamboo', title: 'TitleBamboo', value: 'b' },
{ label: 'little', value: 'l' },
{ label: 'Rest', value: 'r' },
]}
/>,
);
wrapper.setProps({autoClearSearchValue:true})
wrapper.find('input').simulate('change', { target: { value: 'Two2' } });
selectItem(wrapper, );
expect(wrapper.find('input').prop('value')).toBe('');
});

});