Skip to content

Commit

Permalink
fix(auto-complete): the display effect is abnormal when the option is…
Browse files Browse the repository at this point in the history
… empty
  • Loading branch information
betavs committed Jan 7, 2025
1 parent 7d321e9 commit e7279a3
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/auto-complete/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CommonClassNameType } from '../hooks/useCommonClassName';
import { AutoCompleteOptionObj, TdAutoCompleteProps } from './type';
import HighlightOption from './HighlightOption';
import { on, off } from '../_util/dom';
import Empty from '../empty';

export interface OptionsListProps {
sizeClassNames: CommonClassNameType['sizeClassNames'];
Expand All @@ -18,7 +19,7 @@ export interface OptionsListProps {
highlightKeyword: boolean;
filterable: boolean;
filter: TdAutoCompleteProps['filter'];
onSelect?: (keyword: string, context: { e: MouseEvent<HTMLLIElement> | KeyboardEvent | any }) => void;
onSelect: (keyword: string, context: { e: MouseEvent<HTMLLIElement> | KeyboardEvent | any }) => void;
}

export interface OptionsListRef {
Expand Down Expand Up @@ -81,7 +82,7 @@ const OptionsList = forwardRef<OptionsListRef, OptionsListProps>((props: Options
}
const keyword = liNode.getAttribute('title');
setActive(keyword);
onSelect?.(keyword, { e });
onSelect(keyword, { e });
};

// 键盘事件,上下选择
Expand All @@ -90,10 +91,10 @@ const OptionsList = forwardRef<OptionsListRef, OptionsListProps>((props: Options
const currentIndex = activeIndexRef.current;

if (currentIndex === -1) {
return
return;
}

onSelect?.(tOptions[activeIndexRef.current].text, { e });
onSelect(tOptions[activeIndexRef.current].text, { e });
} else {
const index = activeIndexRef.current;
let newIndex;
Expand Down Expand Up @@ -141,7 +142,7 @@ const OptionsList = forwardRef<OptionsListRef, OptionsListProps>((props: Options
activeIndexRef.current = tOptions.findIndex((item) => item.text === active);
}, [active, tOptions]);

if (!tOptions.length) return null;
if (!tOptions.length) return <Empty />;
return (
<ul className={classes}>
{tOptions.map((item) => {
Expand Down

0 comments on commit e7279a3

Please sign in to comment.