fix: Select and shadcn FieldWrapper component
Fixes: #190 (dual error in array field), #180, #182, and other select-related issues.
One thing I’d like to confirm — should the <SelectItem> value remain as key (as before), or should we use the label ?
Ant and MUI use the label as the value, whereas Chakra, Mantine, and shadcn use the key.
<SelectItem key={key} value={key}>
{label}
</SelectItem>
@adityacodepublic is attempting to deploy a commit to the vantezzen Team on Vercel.
A member of the Team first needs to authorize it.
I think maybe using the key makes more sense? I feel like label sounds more like a user-facing/display-only property than a unique way to identify values? And IIRC zod is also more focused on that.
So should I update Ant and MUI to use key ?
Yes that would be good to have full consistency!
⚠️ No Changeset found
Latest commit: 6b68e975ebed14f59fd522a29d6504f7263095f8
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
But for
enum Sports {
Football = "Football/Soccer",
Basketball = "Basketball",
Baseball = "Baseball",
Hockey = "Hockey (Ice)",
None = "I don't like sports",
}
key will be available only with zod schemas.
for yup and joi schemas the key and label will be same,
as they don't provide keys of enum in their schema.
Depending on the use case, the user may require either the label or the id (key) as the selected value from the form
there should be a way to provide label and id (key) in the options ?
Oh I didn't know that about joi and yup! That's difficult, I think at the end zod expects the key as the value otherwise the schema is invalid, right?
Zod, Yup, and Joi all expect enum values (ie: labels) as valid inputs for schema validation.
Previously, Select tests passed because Select, enums weren’t used in basic.cy tests,
and if enum have same key and value the validation would pass eg. Basketball = "Basketball"
So, I've updated Shadcn and Mantine SelectField to use the enum values (ie: labels) (all SelectField components use labels)
Now added tests for all Select components using a TypeScript enum
enum Sports { Football = "Football/Soccer", Basketball = "Basketball", Baseball = "Baseball", Hockey = "Hockey (Ice)", None = "I don't like sports", }