|
1 | 1 | <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"> |
5 | 3 | <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" |
7 | 6 | :disabled="loading || value <= min"
|
8 | 7 | @click="updateValue(value - 1)"
|
9 |
| - aria-label="Decrease quantity" |
10 | 8 | type="button"
|
11 | 9 | >-</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 | + /> |
15 | 22 | <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" |
17 | 25 | :disabled="loading || (max !== null && value >= max)"
|
18 | 26 | @click="updateValue(value + 1)"
|
19 |
| - aria-label="Increase quantity" |
20 | 27 | type="button"
|
21 | 28 | >+</button>
|
22 | 29 | </div>
|
@@ -54,4 +61,11 @@ function updateValue(newValue) {
|
54 | 61 | if (newValue < props.min) return;
|
55 | 62 | emit("update:modelValue", newValue);
|
56 | 63 | }
|
| 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 | +} |
57 | 71 | </script>
|
0 commit comments