diff --git a/src/auto-complete/AutoComplete.tsx b/src/auto-complete/AutoComplete.tsx index ee8392b5fb..12f1ac1224 100644 --- a/src/auto-complete/AutoComplete.tsx +++ b/src/auto-complete/AutoComplete.tsx @@ -63,6 +63,9 @@ const AutoComplete = forwardRef((originalPro })(); const onInputChange: TdInputProps['onChange'] = (value, context) => { + if (!popupVisible) { + setPopupVisible(true); + } setTValue(value, context); }; diff --git a/src/auto-complete/OptionList.tsx b/src/auto-complete/OptionList.tsx index 2c6599b584..9aa7c169bc 100644 --- a/src/auto-complete/OptionList.tsx +++ b/src/auto-complete/OptionList.tsx @@ -27,7 +27,7 @@ export interface OptionsListRef { } const OptionsList = forwardRef((props: OptionsListProps, ref) => { - const { value, onSelect, popupVisible } = props; + const { value, popupVisible, onSelect } = props; const { classPrefix } = useConfig(); const [active, setActive] = useState(''); const activeIndexRef = useRef(-1); @@ -87,6 +87,12 @@ const OptionsList = forwardRef((props: Options // 键盘事件,上下选择 const onKeyInnerPress = (e: KeyboardEvent) => { if (e.code === 'Enter' || e.key === 'Enter') { + const currentIndex = activeIndexRef.current; + + if (currentIndex === -1) { + return + } + onSelect?.(tOptions[activeIndexRef.current].text, { e }); } else { const index = activeIndexRef.current;