From cdc9f258f29076f664807d93f457c48af7558984 Mon Sep 17 00:00:00 2001 From: liweijie0812 <674416404@qq.com> Date: Thu, 7 Dec 2023 14:03:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(auto-complete):=20=E6=B2=A1=E9=80=89?= =?UTF-8?q?=E4=B8=AD=E4=B8=8D=E8=A7=A6=E5=8F=91=E9=80=89=E4=B8=AD=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=20(#3700)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auto-complete/option-list.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/auto-complete/option-list.tsx b/src/auto-complete/option-list.tsx index 77162f2a6a..4030ea3ebd 100644 --- a/src/auto-complete/option-list.tsx +++ b/src/auto-complete/option-list.tsx @@ -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', @@ -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 }); + } } };