From 681f0e5684feaad0c711130404751f2fd65ddbe4 Mon Sep 17 00:00:00 2001 From: Aditio Pangestu <138564696+aditio-eka@users.noreply.github.com> Date: Wed, 20 Sep 2023 16:06:23 +0700 Subject: [PATCH] fix(FormGroup): use explicit label instead of implicit label (#638) --- src/runtime/components/forms/FormGroup.vue | 40 ++++++++++++--------- src/runtime/components/forms/Input.vue | 11 ++++-- src/runtime/components/forms/Range.vue | 11 ++++-- src/runtime/components/forms/Select.vue | 11 ++++-- src/runtime/components/forms/SelectMenu.vue | 12 +++++-- src/runtime/components/forms/Textarea.vue | 13 ++++--- src/runtime/components/forms/Toggle.vue | 11 ++++-- src/runtime/composables/useFormGroup.ts | 14 ++++++-- src/runtime/types/form.d.ts | 7 ++++ 9 files changed, 95 insertions(+), 35 deletions(-) diff --git a/src/runtime/components/forms/FormGroup.vue b/src/runtime/components/forms/FormGroup.vue index baf0b62e33..465fbcda14 100644 --- a/src/runtime/components/forms/FormGroup.vue +++ b/src/runtime/components/forms/FormGroup.vue @@ -1,20 +1,21 @@ @@ -23,7 +24,7 @@ import { computed, defineComponent, provide, inject } from 'vue' import type { PropType } from 'vue' import { omit } from '../../utils/lodash' import { twMerge } from 'tailwind-merge' -import type { FormError } from '../../types/form' +import type { FormError, InjectedFormGroupValue } from '../../types/form' import { defuTwMerge } from '../../utils' import { useAppConfig } from '#imports' // TODO: Remove @@ -32,6 +33,8 @@ import appConfig from '#build/app.config' // const appConfig = useAppConfig() +let increment = 0 + export default defineComponent({ inheritAttrs: false, props: { @@ -92,14 +95,17 @@ export default defineComponent({ }) const size = computed(() => ui.value.size[props.size ?? appConfig.ui.input.default.size]) + const labelFor = ref(`${props.name || 'lf'}-${increment = increment < 1000000 ? increment + 1 : 0}`) - provide('form-group', { + provide('form-group', { error, + labelFor, name: computed(() => props.name), size: computed(() => props.size) }) return { + labelFor, attrs: computed(() => omit(attrs, ['class'])), // eslint-disable-next-line vue/no-dupe-keys ui, diff --git a/src/runtime/components/forms/Input.vue b/src/runtime/components/forms/Input.vue index 197f04a891..3321332223 100644 --- a/src/runtime/components/forms/Input.vue +++ b/src/runtime/components/forms/Input.vue @@ -1,6 +1,7 @@