Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,26 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
};

// Close will clean up single mode search text
// Use ref to avoid adding emptyListContent to dependencies
const emptyListContentRef = React.useRef(emptyListContent);
emptyListContentRef.current = emptyListContent;

const prevOpenRef = React.useRef(mergedOpen);
React.useEffect(() => {
if (!mergedOpen && !multiple && mode !== 'combobox') {
// Only clean search value when dropdown actually closes (true -> false)
// Skip when emptyListContent is true - this means dropdown was forced closed
// due to no matching options and notFoundContent being null,
// user should still be able to continue typing
if (
prevOpenRef.current &&
!mergedOpen &&
!multiple &&
mode !== 'combobox' &&
!emptyListContentRef.current
) {
onInternalSearch('', false, false);
}
prevOpenRef.current = mergedOpen;
}, [mergedOpen]);

// ============================ Disabled ============================
Expand Down
28 changes: 28 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,34 @@ describe('Select.Basic', () => {
expect(container.querySelector('.rc-select-dropdown-empty')).toBeFalsy();
});

it('should allow typing when notFoundContent is null and no options match', () => {
const onSearch = jest.fn();
const { container } = render(
<Select showSearch notFoundContent={null} onSearch={onSearch}>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
</Select>,
);

const input = container.querySelector('input');

// Type 'j' - should match 'Jack'
fireEvent.change(input, { target: { value: 'j' } });
expect(onSearch).toHaveBeenLastCalledWith('j');
expect(input.value).toBe('j');
expect(container.querySelectorAll('.rc-select-item-option')).toHaveLength(1);

// Type 'x' - no match, but input should still work
fireEvent.change(input, { target: { value: 'x' } });
expect(onSearch).toHaveBeenLastCalledWith('x');
expect(input.value).toBe('x');

// Type more characters - should continue working
fireEvent.change(input, { target: { value: 'xyz' } });
expect(onSearch).toHaveBeenLastCalledWith('xyz');
expect(input.value).toBe('xyz');
});

it('click outside to close select', () => {
jest.useFakeTimers();

Expand Down