Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
notFoundContent,
open: mergedOpen,
triggerOpen: mergedOpen,
rawOpen,
id,
showSearch,
multiple,
Expand All @@ -662,6 +663,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
showSearch,
multiple,
mergedOpen,
rawOpen,
showScrollBar,
styles,
classNames,
Expand Down
4 changes: 3 additions & 1 deletion src/SelectInput/Content/MultipleContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M
disabled,
showSearch,
triggerOpen,
rawOpen,
toggleOpen,
autoClearSearchValue,
tagRender: tagRenderFromContext,
Expand All @@ -50,8 +51,9 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function M

// ===================== Search ======================
// Apply autoClearSearchValue logic: when dropdown is closed and autoClearSearchValue is not false (default true), clear search value
// Use rawOpen to avoid clearing search when emptyListContent blocks open
let computedSearchValue = searchValue;
if (!triggerOpen && mode === 'multiple' && autoClearSearchValue !== false) {
if (!rawOpen && mode === 'multiple' && autoClearSearchValue !== false) {
computedSearchValue = '';
}

Expand Down
1 change: 1 addition & 0 deletions src/hooks/useBaseProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { BaseSelectProps } from '../BaseSelect';

export interface BaseSelectContextProps extends BaseSelectProps {
triggerOpen: boolean;
rawOpen: boolean;
multiple: boolean;
toggleOpen: (open?: boolean) => void;
lockOptions: boolean;
Expand Down
53 changes: 29 additions & 24 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1997,32 +1997,37 @@ 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>,
);
describe('should allow typing when notFoundContent is null and no options match', () => {
it.each<{ mode: 'multiple' | undefined; label: string }>([
{ mode: undefined, label: 'single' },
{ mode: 'multiple', label: 'multiple' },
])('$label', ({ mode }) => {
const onSearch = jest.fn();
const { container } = render(
<Select mode={mode} showSearch notFoundContent={null} onSearch={onSearch}>
<Option value="jack">Jack</Option>
<Option value="lucy">Lucy</Option>
</Select>,
);

const input = container.querySelector('input');
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 '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');
// 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', () => {
Expand Down
Loading