Skip to content

Commit afdf9c5

Browse files
committed
fix: display logic
1 parent f71f4c5 commit afdf9c5

File tree

4 files changed

+22
-8
lines changed

4 files changed

+22
-8
lines changed

src/BaseSelect/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
395395
);
396396

397397
// ============================== Open ==============================
398-
// Not trigger `open` in `combobox` when `notFoundContent` is empty
398+
// Not trigger `open` when `notFoundContent` is empty
399399
const emptyListContent = !notFoundContent && emptyOptions;
400400

401401
const [mergedOpen, triggerOpen] = useOpen(open, onPopupVisibleChange, (nextOpen) =>
402-
disabled || (emptyListContent && mergedOpen && mode === 'combobox') ? false : nextOpen,
402+
disabled || emptyListContent ? false : nextOpen,
403403
);
404404

405405
// // SSR not support Portal which means we need delay `open` for the first time render

src/SelectInput/Content/SingleContent.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function S
2222
const displayValue = displayValues[0];
2323

2424
// Implement the same logic as the old SingleSelector
25-
let mergedSearchValue: string = searchValue || '';
26-
if (combobox && activeValue && !inputChanged && triggerOpen) {
27-
mergedSearchValue = activeValue;
28-
}
25+
const mergedSearchValue = React.useMemo(() => {
26+
if (combobox && activeValue && !inputChanged && triggerOpen) {
27+
return activeValue;
28+
}
29+
30+
return searchValue || '';
31+
}, [combobox, activeValue, inputChanged, triggerOpen, searchValue]);
2932

3033
// Extract option props, excluding label and value, and handle className/style merging
3134
const optionProps = React.useMemo(() => {
32-
let restProps = {
35+
let restProps: React.HTMLAttributes<HTMLDivElement> = {
3336
className: `${prefixCls}-content-value`,
3437
style: {
3538
visibility: mergedSearchValue ? 'hidden' : 'visible',

src/utils/keyUtil.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export function isValidateOpenKey(currentKeyCode: number): boolean {
2222
KeyCode.EQUALS,
2323
KeyCode.CAPS_LOCK,
2424
KeyCode.CONTEXT_MENU,
25+
// Arrow keys - should not trigger open when navigating in input
26+
KeyCode.UP,
27+
KeyCode.DOWN,
28+
KeyCode.LEFT,
29+
KeyCode.RIGHT,
2530
// F1-F12
2631
KeyCode.F1,
2732
KeyCode.F2,

tests/shared/inputFilterTest.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as React from 'react';
22
import Option from '../../src/Option';
33
import Select from '../../src/Select';
4-
import { fireEvent, render } from '@testing-library/react';
4+
import { act, fireEvent, render } from '@testing-library/react';
55

66
export default function inputFilterTest(mode: any) {
77
it('should keep input filter after select when autoClearSearchValue is false', () => {
8+
jest.useFakeTimers();
9+
810
const { container } = render(
911
<Select mode={mode} autoClearSearchValue={false} showSearch>
1012
<Option value="11">11</Option>
@@ -22,7 +24,11 @@ export default function inputFilterTest(mode: any) {
2224
expect(container.querySelector('.rc-select')).toHaveClass('rc-select-open');
2325
expect(container.querySelector('input')).toHaveValue('1');
2426
fireEvent.click(container.querySelector('.rc-select-item-option'));
27+
act(() => {
28+
jest.runAllTimers();
29+
});
2530
expect(container.querySelector('input')).toHaveValue(mode === 'single' ? '' : '1');
31+
jest.useRealTimers();
2632
});
2733

2834
it('should clear input filter after select', () => {

0 commit comments

Comments
 (0)