Skip to content

Commit 2b37d34

Browse files
authored
fix: Close popup should clean up input (#478)
* clear content when lose focus * test case
1 parent 2bafaa5 commit 2b37d34

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Selector/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ const Selector: React.RefForwardingComponent<RefSelectorProps, SelectorProps> =
186186
}
187187

188188
if ((mode !== 'combobox' && (!showSearch || !inputMouseDown)) || !open) {
189+
if (open) {
190+
onSearch('');
191+
}
189192
onToggleOpen();
190193
}
191194
};

tests/Multiple.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,16 @@ describe('Select.Multiple', () => {
279279
toggleOpen(wrapper);
280280
expect(wrapper.find('.rc-select-selection-placeholder').length).toBeFalsy();
281281
});
282+
283+
it('clear input when popup closed', () => {
284+
const wrapper = mount(<Select mode="multiple" options={[{ value: 'light' }]} showSearch />);
285+
toggleOpen(wrapper);
286+
wrapper.find('input').simulate('change', { target: { value: 'bamboo' } });
287+
expect(wrapper.find('input').props().value).toEqual('bamboo');
288+
289+
// Close and open again
290+
toggleOpen(wrapper);
291+
toggleOpen(wrapper);
292+
expect(wrapper.find('input').props().value).toEqual('');
293+
});
282294
});

0 commit comments

Comments
 (0)