Skip to content

Commit

Permalink
make number field aware of false inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilReinking committed Feb 18, 2024
1 parent 1d204c0 commit 44da38e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 16.20.2
nodejs 18.19.1
9 changes: 6 additions & 3 deletions src/Input/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
:tabindex="isDisabled ? '-1' : undefined"
:value="localValue"
v-bind="$attrs"
ref="input"
ref="inputElement"
@input="onInput"
/>

Expand Down Expand Up @@ -86,6 +86,7 @@ const props = withDefaults(
}
);
const inputElement = ref(null) as unknown as Ref<HTMLInputElement>;
const localValue = ref<string | number | null>(props.modelValue ?? "");
watch(
Expand Down Expand Up @@ -130,14 +131,16 @@ watch(sRGBHex, (value) => {
const onInput = function (payload: Event): void {
const value = (payload?.target as InputHTMLAttributes).value;
if (props.min && parseInt(value) < props.min) {
if (props.type === "number" && props.min && parseInt(value) < props.min) {
localValue.value = props.min;
inputElement.value.value = localValue.value.toString();
emit("update:modelValue", props.min);
return;
}
if (props.max && parseInt(value) > props.max) {
if (props.type === "number" && props.max && parseInt(value) > props.max) {
localValue.value = props.max;
inputElement.value.value = localValue.value.toString();
emit("update:modelValue", props.max);
return;
}
Expand Down

0 comments on commit 44da38e

Please sign in to comment.