Skip to content

Commit 9a4d6d3

Browse files
committed
chore: backfill
1 parent f9e8a2c commit 9a4d6d3

6 files changed

Lines changed: 41 additions & 15 deletions

File tree

src/BaseSelect/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
474474
});
475475
}
476476

477+
// Open if from typing
478+
if (searchText && fromTyping) {
479+
triggerOpen(true);
480+
}
481+
477482
return ret;
478483
};
479484

@@ -923,6 +928,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
923928
displayValues={displayValues}
924929
placeholder={placeholder}
925930
searchValue={mergedSearchValue}
931+
activeValue={activeValue}
926932
onSearch={onInternalSearch}
927933
onSearchSubmit={onInternalSearchSubmit}
928934
onInputBlur={onInputBlur}

src/SelectInput/Content/Placeholder.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import * as React from 'react';
22
import { useSelectInputContext } from '../context';
33

4-
export default function Placeholder() {
4+
export interface PlaceholderProps {
5+
hasSearchValue?: boolean;
6+
}
7+
8+
export default function Placeholder(props: PlaceholderProps) {
59
const { prefixCls, placeholder, displayValues } = useSelectInputContext();
610

711
const { searchValue } = useSelectInputContext();
812

13+
const { hasSearchValue = !!searchValue } = props;
14+
915
if (displayValues.length) {
1016
return null;
1117
}
@@ -14,7 +20,7 @@ export default function Placeholder() {
1420
<div
1521
className={`${prefixCls}-placeholder`}
1622
style={{
17-
visibility: searchValue ? 'hidden' : 'visible',
23+
visibility: hasSearchValue ? 'hidden' : 'visible',
1824
}}
1925
>
2026
{placeholder}

src/SelectInput/Content/SingleContent.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,49 @@ export default React.forwardRef<HTMLInputElement, SharedContentProps>(function S
88
{ inputProps },
99
ref,
1010
) {
11-
const { prefixCls, searchValue, displayValues, maxLength, mode } = useSelectInputContext();
11+
const { prefixCls, searchValue, activeValue, displayValues, maxLength, mode, onSearch } =
12+
useSelectInputContext();
1213

14+
const [inputChanged, setInputChanged] = React.useState(false);
15+
16+
const combobox = mode === 'combobox';
1317
const displayValue = displayValues[0];
1418

19+
// Implement the same logic as the old SingleSelector
20+
let mergedSearchValue: string = searchValue || '';
21+
if (combobox && activeValue && !inputChanged) {
22+
mergedSearchValue = activeValue;
23+
}
24+
25+
React.useEffect(() => {
26+
if (combobox) {
27+
setInputChanged(false);
28+
}
29+
}, [combobox, activeValue]);
30+
1531
return (
1632
<div className={`${prefixCls}-content`}>
1733
{displayValue ? (
1834
<div
1935
className={`${prefixCls}-content-value`}
2036
style={{
21-
visibility: searchValue ? 'hidden' : 'visible',
37+
visibility: mergedSearchValue ? 'hidden' : 'visible',
2238
}}
2339
>
2440
{displayValue.label}
2541
</div>
2642
) : (
27-
<Placeholder />
43+
<Placeholder hasSearchValue={!!mergedSearchValue} />
2844
)}
2945
<Input
3046
ref={ref}
3147
{...inputProps}
32-
value={searchValue}
48+
value={mergedSearchValue}
3349
maxLength={mode === 'combobox' ? maxLength : undefined}
50+
onChange={(e) => {
51+
setInputChanged(true);
52+
inputProps.onChange?.(e);
53+
}}
3454
/>
3555
</div>
3656
);

src/SelectInput/Input.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ export interface InputProps {
1313
className?: string;
1414
style?: React.CSSProperties;
1515
maxLength?: number;
16-
[key: string]: any;
1716
}
1817

1918
const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
2019
const { onChange, onKeyDown, onBlur, ...restProps } = props;
21-
const { prefixCls, mode, onSearch, onSearchSubmit, onInputBlur, onInputKeyDown, autoFocus } =
20+
const { prefixCls, mode, onSearch, onSearchSubmit, onInputBlur, autoFocus } =
2221
useSelectInputContext();
2322

2423
const inputCls = `${prefixCls}-input`;
@@ -44,12 +43,6 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>((props, ref) => {
4443
const { key } = event;
4544
const { value } = event.currentTarget;
4645

47-
// Call the internal keyboard handler from context first
48-
// This handles up/down arrow prevention and validate open keys
49-
if (onInputKeyDown) {
50-
onInputKeyDown(event);
51-
}
52-
5346
// Handle Enter key submission - referencing Selector implementation
5447
if (key === 'Enter' && mode === 'tags' && !compositionStatusRef.current && onSearchSubmit) {
5548
onSearchSubmit(value);

src/SelectInput/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface SelectInputProps extends Omit<React.HTMLAttributes<HTMLDivEleme
2020
displayValues: DisplayValueType[];
2121
placeholder?: React.ReactNode;
2222
searchValue?: string;
23+
activeValue?: string;
2324
mode?: Mode;
2425
onSearch?: (searchText: string, fromTyping: boolean, isCompositing: boolean) => void;
2526
onSearchSubmit?: (searchText: string) => void;

tests/Combobox.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ describe('Select.Combobox', () => {
319319
onChange.mockReset();
320320

321321
keyDown(inputEle, KeyCode.DOWN);
322-
expect(inputEle.value).toEqual('light@gmail.com');
322+
expect(inputEle).toHaveValue('light@gmail.com');
323323
expect(onChange).not.toHaveBeenCalled();
324324

325325
keyDown(inputEle, KeyCode.ENTER);

0 commit comments

Comments
 (0)