From fec2e600c3cc1ceea0e19cdc87a0b7036b74d468 Mon Sep 17 00:00:00 2001 From: pwli0755 Date: Wed, 28 Aug 2024 15:04:12 +0800 Subject: [PATCH] chore: enable multiple-type toggle-group in shadcn-ui examples --- examples/shadcn-ui/src/App.tsx | 22 ++++++++++++++++++- .../src/components/conform/ToggleGroup.tsx | 22 +++++++++++++++---- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/examples/shadcn-ui/src/App.tsx b/examples/shadcn-ui/src/App.tsx index ecd99efb..5d551746 100644 --- a/examples/shadcn-ui/src/App.tsx +++ b/examples/shadcn-ui/src/App.tsx @@ -44,6 +44,7 @@ const UserSubscriptionSchema = z.object({ accountType: z.enum(['personal', 'business'], { required_error: 'You must select an account type', }), + accountTypes: z.array(z.enum(['personal', 'business'])), interests: z .array(z.string()) .min(3, 'You must select at least three interest'), @@ -54,7 +55,11 @@ function App() { const [form, fields] = useForm({ id: 'signup', onValidate({ formData }) { - return parseWithZod(formData, { schema: UserSubscriptionSchema }); + const result = parseWithZod(formData, { schema: UserSubscriptionSchema }); + if (result.status==='error') { + console.error(result); + } + return result }, onSubmit(e) { e.preventDefault(); @@ -164,6 +169,21 @@ function App() { {fields.accountType.errors} )} + + + + {fields.accountTypes.errors && ( + {fields.accountTypes.errors} + )} +
Interests
; - meta: FieldMetadata; + meta: FieldMetadata; } & Omit, 'defaultValue'>) => { const toggleGroupRef = useRef>(null); - const control = useControl(meta); + const control = useControl(meta); return ( <> - { toggleGroupRef.current?.focus(); }} - /> + /> : control.value ? (control.value as string[]).map(v => { }} + onFocus={() => { + toggleGroupRef.current?.focus(); + }} + />) : null} + {