Skip to content

Commit

Permalink
feat(auto-complete): 没选中不触发选中事件 (#3700)
Browse files Browse the repository at this point in the history
  • Loading branch information
liweijie0812 authored Dec 7, 2023
1 parent 951255a commit cdc9f25
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/auto-complete/option-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { usePrefixClass } from '../hooks/useConfig';
import { on, off } from '../utils/dom';
import isString from 'lodash/isString';
import escapeRegExp from 'lodash/escapeRegExp';
import { ARROW_UP_REG, ARROW_DOWN_REG, ENTER_REG } from '../_common/js/common';

export default defineComponent({
name: 'AutoCompleteOptionList',
Expand Down Expand Up @@ -82,16 +83,18 @@ export default defineComponent({

// 键盘事件,上下选择
const onKeyInnerPress = (e: KeyboardEvent) => {
if (e.code === 'ArrowUp' || e.key === 'ArrowUp') {
if (ARROW_UP_REG.test(e.code) || ARROW_UP_REG.test(e.key)) {
const index = tOptions.value.findIndex((item) => item.text === active.value);
const newIndex = index - 1 < 0 ? tOptions.value.length - 1 : index - 1;
active.value = tOptions.value[newIndex]?.text;
} else if (e.code === 'ArrowDown' || e.key === 'ArrowDown') {
} else if (ARROW_DOWN_REG.test(e.code) || ARROW_DOWN_REG.test(e.key)) {
const index = tOptions.value.findIndex((item) => item.text === active.value);
const newIndex = index + 1 >= tOptions.value.length ? 0 : index + 1;
active.value = tOptions.value[newIndex]?.text;
} else if (e.code === 'Enter' || e.key === 'Enter') {
emit('select', active.value, { e });
} else if (ENTER_REG.test(e.code) || ENTER_REG.test(e.key)) {
if (active.value) {
emit('select', active.value, { e });
}
}
};

Expand Down

0 comments on commit cdc9f25

Please sign in to comment.