feat(Form): new component (#439)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Romain Hamel
2023-07-31 15:22:14 +02:00
committed by GitHub
parent c37a927b4e
commit a3aba1abad
22 changed files with 945 additions and 17 deletions

View File

@@ -13,6 +13,7 @@
:class="textareaClass"
v-bind="$attrs"
@input="onInput"
@blur="onBlur"
/>
</div>
</template>
@@ -22,6 +23,7 @@ import { ref, computed, watch, onMounted, nextTick, defineComponent } from 'vue'
import type { PropType } from 'vue'
import { defu } from 'defu'
import { classNames } from '../../utils'
import { useFormEvents } from '../../composables/useFormEvents'
import { useAppConfig } from '#imports'
// TODO: Remove
// @ts-expect-error
@@ -101,7 +103,7 @@ export default defineComponent({
default: () => appConfig.ui.textarea
}
},
emits: ['update:modelValue'],
emits: ['update:modelValue', 'blur'],
setup (props, { emit }) {
const textarea = ref<HTMLTextAreaElement | null>(null)
@@ -110,6 +112,8 @@ export default defineComponent({
const ui = computed<Partial<typeof appConfig.ui.textarea>>(() => defu({}, props.ui, appConfig.ui.textarea))
const { emitFormBlur } = useFormEvents()
const autoFocus = () => {
if (props.autofocus) {
textarea.value?.focus()
@@ -144,6 +148,17 @@ export default defineComponent({
emit('update:modelValue', (event.target as HTMLInputElement).value)
}
const onBlur = (event: FocusEvent) => {
emitFormBlur()
emit('blur', event)
}
onMounted(() => {
setTimeout(() => {
autoFocus()
}, 100)
})
watch(() => props.modelValue, () => {
nextTick(autoResize)
})
@@ -174,7 +189,8 @@ export default defineComponent({
ui,
textarea,
textareaClass,
onInput
onInput,
onBlur
}
}
})