-
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
fix(FormGroup): ensure size exists in config #695
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
const size = computed(() => formGroup?.size?.value ?? props.size) | ||
const size = computed(() => { | ||
const size = formGroup?.size?.value ?? props.size | ||
if (!ui.value.size[size.value] || |
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 think we don't need to check too many, that issue happens because the range
component do not support the xl
size from formGroup
.
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.
agree, is it better now?
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 would prefer return to props.size
, that might be better for users want to define range size
themselves, and it has default value already.
Return to default will overwrite the size
passed by range
if range
not support formGroup 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.
done
@@ -89,7 +89,13 @@ export default defineComponent({ | |||
|
|||
const { emitFormChange, formGroup } = useFormGroup() | |||
const color = computed(() => formGroup?.error?.value ? 'red' : props.color) | |||
const size = computed(() => formGroup?.size?.value ?? props.size) | |||
const size = computed(() => { |
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.
#704 had conflicts with it, maybe this PR needs to take another look ...
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 have pulled the dev and I returned the size.default
as a fallback according to the #704 MR
@@ -92,7 +92,8 @@ export default defineComponent({ | |||
setup (props, { emit }) { | |||
const { ui, attrs, attrsClass } = useUI('range', props.ui, config) | |||
|
|||
const { emitFormChange, inputId, color, size, name } = useFormGroup(props, config) | |||
const { emitFormChange, inputId, color, size: formGroupSize, name } = useFormGroup(props, config) | |||
const size = computed(() => ui.value.size[formGroupSize] ? formGroupSize : config.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.
const size = computed(() => ui.value.size[formGroupSize] ? formGroupSize : config.default?.size) | |
const size = computed(() => ui.value.size[formGroupSize] ? formGroupSize : (props.size ?? config.default?.size)) |
How about this ? I'm not sure if range
component still need to custom in formGroup
thou.
const { emitFormChange, inputId, color, size, name } = useFormGroup(props, config) | ||
const { emitFormChange, inputId, color, size: formGroupSize, name } = useFormGroup(props, config) | ||
const size = computed(() => ui.value.size[formGroupSize] ? formGroupSize : (props.size ?? config.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.
I recently refactored how FormGroup props are injected (#704), it might be better to do this check for all inputs by doing here: https://github.com/nuxt/ui/blob/dev/src/runtime/composables/useFormGroup.ts#L47
Also, props.size
should have priority over formGroupSize
I guess something like this should work?
# useFormGroup.ts
export const useFormGroup = (...) => {
return {
// ...
size: computed(() => {
const formGroupSize = config.sizes[formGroup?.size.value] ? formGroup?.size.value : undefined
return inputProps?.size ?? formGroupSize ?? config?.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.
@romhml , could you 2-check the last commit, pls?
And I think we really should add types to the ui.config.ts
- file..... It would be great to use types inside useUI
or useFormGroup
instead of any. Am I wrong, or i can create an issue for it?
Also, wouldn't it make sense to have the same size variants for all components, or at least inputs to avoid that kind of edge cases? @benjamincanac |
|
The latest commit cannot deploy |
|
Try the same code as issue at playground and will return 500. It can't read |
Co-authored-by: Sma11X <540351143@qq.com>
@@ -92,7 +92,7 @@ export default defineComponent({ | |||
setup (props, { emit }) { | |||
const { ui, attrs, attrsClass } = useUI('range', props.ui, config) | |||
|
|||
const { emitFormChange, inputId, color, size, name } = useFormGroup(props, config) | |||
const { emitFormChange, inputId, color, size, name } = useFormGroup(props, ui) |
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 { emitFormChange, inputId, color, size, name } = useFormGroup(props, ui) | |
const { emitFormChange, inputId, color, size, name } = useFormGroup(props, config) |
@benjamincanac I agree, it's still good idea to fallback to the default input's size if the one provided by the FormGroup is not defined, to handle cases where a user defines custom sizes. |
Closes #673.