Skip to content

Commit 84249e7

Browse files
committed
feat: UInputCounter: add ArrowUp/ArrowDown keyboard navigation for increment/decrement actions
1 parent 496727e commit 84249e7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/ui.form-input-counter/UInputCounter.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,24 @@ function onInput() {
154154
setInputSize();
155155
}
156156
157+
function onKeyDown(event: KeyboardEvent) {
158+
if (event.key === "ArrowUp") {
159+
event.preventDefault();
160+
161+
if (!isAddButtonDisabled.value && !props.disabled) {
162+
onClickAdd();
163+
}
164+
}
165+
166+
if (event.key === "ArrowDown") {
167+
event.preventDefault();
168+
169+
if (!isSubtractButtonDisabled.value && !props.disabled) {
170+
onClickSubtract();
171+
}
172+
}
173+
}
174+
157175
function setInputSize() {
158176
if (inputComponentRef.value && !props.readonly) {
159177
inputComponentRef.value.inputRef?.setAttribute(
@@ -222,6 +240,7 @@ const {
222240
@focus="onFocus"
223241
@blur="onBlur"
224242
@input="onInput"
243+
@keydown="onKeyDown"
225244
/>
226245

227246
<UButton

0 commit comments

Comments
 (0)