fix: default input props not reactive

This commit is contained in:
parasSolanki 2023-12-29 20:24:46 +05:30
parent c75b40245f
commit fa0cae16b6

View File

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { useAttrs } from 'vue' import { computed, useAttrs } from 'vue'
import { useVModel } from '@vueuse/core' import { useVModel } from '@vueuse/core'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
@ -16,7 +16,13 @@ const emits = defineEmits<{
(e: 'update:modelValue', payload: string | number): void (e: 'update:modelValue', payload: string | number): void
}>() }>()
const { class: className, ...rest } = useAttrs() const rawAttrs = useAttrs()
const attrs = computed(() => {
const { class: className, ...rest } = rawAttrs
return { className, rest }
})
const modelValue = useVModel(props, 'modelValue', emits, { const modelValue = useVModel(props, 'modelValue', emits, {
passive: true, passive: true,
@ -25,5 +31,5 @@ const modelValue = useVModel(props, 'modelValue', emits, {
</script> </script>
<template> <template>
<input v-model="modelValue" :class="cn('flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', className ?? '')" v-bind="rest"> <input v-model="modelValue" :class="cn('flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50', attrs.className ?? '')" v-bind="attrs.rest">
</template> </template>