Skip to content

Commit 57b12e2

Browse files
committed
chore: text input allow numbers
1 parent bb5df64 commit 57b12e2

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

app/components/Input/Text.vue

+23-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const props = defineProps<{
55
id?: string;
66
placeholder: string;
77
8-
modelValue?: string | null;
8+
modelValue?: string | number | null;
99
inputClass?: string;
1010
labelClass?: string;
1111
typeOverride?: string;
@@ -16,13 +16,31 @@ const props = defineProps<{
1616
}>();
1717
1818
const model = useVModel(props, 'modelValue');
19+
const localModel = ref<string>();
20+
21+
watch(localModel, (v) => {
22+
if (!v) return;
23+
if (props.typeOverride && props.typeOverride === 'number') {
24+
model.value = parseFloat(v);
25+
} else {
26+
model.value = v;
27+
}
28+
});
1929
</script>
2030

2131
<template>
22-
<fieldset>
23-
<InputLabel :label-class :label :error :id :sublabel />
24-
<input class="input-css" :type="typeOverride || 'text'" :class="inputClass" v-model="model" :placeholder :id />
25-
</fieldset>
32+
<InputLabel :label-class :label :error :id :sublabel>
33+
<template #input>
34+
<input
35+
class="input-css"
36+
:type="typeOverride || 'text'"
37+
:class="inputClass"
38+
v-model="localModel"
39+
:placeholder
40+
:id
41+
/>
42+
</template>
43+
</InputLabel>
2644
</template>
2745

2846
<style scoped>

0 commit comments

Comments
 (0)