Skip to content

Commit

Permalink
feat(input-number): add keydown event
Browse files Browse the repository at this point in the history
  • Loading branch information
flsion committed Jul 26, 2024
1 parent 6e7269c commit fbfb6ec
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/web-vue/components/input-number/input-number.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
import {
computed,
defineComponent,
nextTick,
PropType,
ref,
toRefs,
watch,
} from 'vue';
import { computed, defineComponent, PropType, ref, toRefs, watch } from 'vue';
import NP from 'number-precision';
import { getPrefixCls } from '../_utils/global-config';
import { isNumber, isUndefined } from '../_utils/is';
Expand Down Expand Up @@ -202,6 +194,13 @@ export default defineComponent({
* @version 2.27.0
*/
'input': (value: number | undefined, inputValue: string, ev: Event) => true,
/**
* @zh 按下键盘时触发
* @en Triggered on keydown
* @param {MouseEvent} ev
* @version 2.56.0
*/
'keydown': (ev: KeyboardEvent) => true,
},
/**
* @zh 前缀
Expand Down Expand Up @@ -430,7 +429,7 @@ export default defineComponent({
emit('clear', ev);
};

const onKeyDown = getKeyDownHandler(
const keyDownHandler = getKeyDownHandler(
new Map([
[
KEYBOARD_KEY.ARROW_UP,
Expand All @@ -449,6 +448,13 @@ export default defineComponent({
])
);

const onKeyDown = (event: KeyboardEvent) => {
emit('keydown', event);
if (!event.defaultPrevented) {
keyDownHandler(event);
}
};

watch(
() => props.modelValue,
(value: number | undefined) => {
Expand Down

0 comments on commit fbfb6ec

Please sign in to comment.