-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(FormGroup): simplify bindings between input and form group p⦠#704
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) | ||
const size = computed(() => formGroup?.size?.value ?? props.size) | ||
const id = formGroup?.labelFor | ||
const { emitFormBlur, emitFormInput, size, color, inputId, name } = useFormGroup(props) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { emitFormBlur, emitFormInput, size, color, inputId, name } = useFormGroup(props) | |
const { emitFormBlur, emitFormInput, size, color, inputId } = useFormGroup(props) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the name
not used to bind on the <input>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went too fast, fixed it here fb2442b
@@ -38,9 +46,12 @@ export const useFormGroup = (inputAttrs?: InputAttrs) => { | |||
}, 300) | |||
|
|||
return { | |||
inputId: formGroup?.inputId, | |||
name: computed(() => inputProps?.name ?? formGroup?.name), | |||
size: computed(() => inputProps?.size ?? formGroup?.size?.value ?? appConfig.ui.input.default.size), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately appConfig.ui.input.default.size
won't work here as the default config no longer lives in the appConfig
, it's only the one from the user. You can take a look at the FormGroup
: https://github.com/nuxt/ui/pull/704/files#diff-82ffaa8fe9c377bdfd6259594303b0111befc57be8db4b95e1e1d4cd0d3eb56dR30
import { formGroup } from '#ui/ui.config'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I looked into it, looks like it's going to be a bit more complicated than I imagined, the default value needs to be set to the input's default (not the form group), it might make more sense move this back into each components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you can take the default from the input
as most of the other form elements inherit from its config. This could lead to an edge-case if the user changes the config entirely but I think its good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed it by providing the configuration object in the composable to avoid edge-cases, what do you think?
@@ -80,7 +80,7 @@ async function submit (event: FormSubmitEvent<Schema>) { | |||
</UFormGroup> | |||
|
|||
<UFormGroup name="checkbox" label="Checkbox"> | |||
<UCheckbox v-model="state.checkbox" /> | |||
<UCheckbox v-model="state.checkbox" label="Check me" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add a label
here? This should with UFormGroup
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkbox components and Radio are a bit different from the others because a label is included in the component:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but both behaviour should work, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does clicking on the Checkbox
label (one from FormGroup
) works for you? it doesn't for me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah sorry I could not see straight, just fixed it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The label
of the Radio
components doesn't seem to work while the one from the FormGroup
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, note that clicking on the FormGroup's label for Radio groups does not work properly, I'll fix this in another PR introducing a wrapper component (will also fix #684).
@@ -119,7 +119,7 @@ export default defineComponent({ | |||
}, | |||
size: { | |||
type: String as PropType<keyof typeof config.size>, | |||
default: () => config.default.size, | |||
default: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@romhml Why did you move the default to the useFormGroup
composable?
π Linked issue
#680
β Type of change
π Description
This PR refactors the way the FormGroup component injects props into input components. It also introduces a util function to generate unique unique html identifiers (fixes #680).
In short:
π Checklist