Skip to content

Commit d4b9d81

Browse files
committed
Update CommonInput.vue
1 parent 630e541 commit d4b9d81

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

components/common/CommonInput.vue

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
11
<template>
2-
<div
3-
class="flex items-center border border-gray-200 rounded-xl bg-white px-2 py-1 min-w-[120px] w-fit h-10 justify-center gap-1"
4-
>
2+
<div class="flex items-center gap-2">
53
<button
6-
class="bg-transparent border-none text-gray-900 text-xl w-9 h-9 flex items-center justify-center rounded-lg transition-colors select-none disabled:text-gray-300 disabled:cursor-not-allowed active:bg-gray-100"
4+
aria-label="Decrease quantity by one"
5+
class="minus-button text-xl w-8 h-[34px] flex items-center justify-center rounded bg-gray-100 hover:bg-gray-200 transition disabled:text-gray-300 disabled:cursor-not-allowed"
76
:disabled="loading || value <= min"
87
@click="updateValue(value - 1)"
9-
aria-label="Decrease quantity"
108
type="button"
119
>-</button>
12-
<div class="border-l border-gray-200 h-6 mx-1"></div>
13-
<span class="min-w-8 text-center font-medium text-lg text-gray-900 px-2 select-none">{{ value }}</span>
14-
<div class="border-l border-gray-200 h-6 mx-1"></div>
10+
<input
11+
type="tel"
12+
pattern="\d*"
13+
maxlength="3"
14+
:value="value"
15+
@input="onInput"
16+
class="quantity product-qty border-0 h-[34px] max-w-[50px] text-center bg-white focus:ring-2 focus:ring-blue-500 focus:outline-none text-lg"
17+
:disabled="loading"
18+
aria-label="Quantity"
19+
autocomplete="off"
20+
inputmode="numeric"
21+
/>
1522
<button
16-
class="bg-transparent border-none text-gray-900 text-xl w-9 h-9 flex items-center justify-center rounded-lg transition-colors select-none disabled:text-gray-300 disabled:cursor-not-allowed active:bg-gray-100"
23+
aria-label="Increase quantity by one"
24+
class="plus-button text-xl w-8 h-[34px] flex items-center justify-center rounded bg-gray-100 hover:bg-gray-200 transition disabled:text-gray-300 disabled:cursor-not-allowed"
1725
:disabled="loading || (max !== null && value >= max)"
1826
@click="updateValue(value + 1)"
19-
aria-label="Increase quantity"
2027
type="button"
2128
>+</button>
2229
</div>
@@ -54,4 +61,11 @@ function updateValue(newValue) {
5461
if (newValue < props.min) return;
5562
emit("update:modelValue", newValue);
5663
}
64+
65+
function onInput(e) {
66+
const newValue = Number(e.target.value.replace(/\D/g, ""));
67+
if (props.max !== null && newValue > props.max) return;
68+
if (newValue < props.min) return;
69+
emit("update:modelValue", newValue);
70+
}
5771
</script>

0 commit comments

Comments
 (0)