Get started
Forms
- Label
- Icon label
- Field
- Form
- Frontmatter form
- Questionnaire
- Input
- Input group
- Input OTP
- Password input
- Password strength
- Code input
- Number field
- Tag input
- Textarea
- Checkbox
- Radio group
- Language toggle group
- Emoji appearance toggle group
- Emoji picker
- Avatar picker
- AI provider picker
- Select
- Native select
- Combobox
- Language combobox
- Slider
- Calendar
- Switch
Display
- Alert
- Avatar
- Badge
- Card
- AI provider card
- Model info card
- Model list
- Empty
- Item
- Tree item
- File tree
- Icon media
- File type icon
- Font preview
- Image preview
- Kbd
- Table
- Data table
- Data table column header
- Chart
- Code Block
- Code card
- Markdown view
- Attachment
- Bubble
- Marker
- Message
- Chat message
- Chat suggestion item
- Message scroller
- Trace
- Progress
- Spinner
- Sonner
- Toast
- Unsaved changes toolbar
- Unsaved indicator
- Status indicator
- Permission card
- Separator
- Skeleton
- Animated grid pattern
- Meteors
Layout
Installation#
Upstream's form item ships no files: a form is Field bound to a form
library. So form installs nothing; install Field and the controls the form uses, and the form library:
bash
pnpm dlx shadcn@latest add @zui/fieldbash
npx expo install react-hook-formUsage#
Bind each control with react-hook-form's Controller, and draw it in a Field that is invalid while its
value is, with a FieldError of the value's error:
tsx
import { Controller, useForm } from 'react-hook-form';
import { Button } from '@/components/ui/button';
import { Field, FieldError, FieldGroup, FieldLabel } from '@/components/ui/field';
import { Input } from '@/components/ui/input';
import { Text } from '@/components/ui/text';tsx
const form = useForm({ defaultValues: { title: '' } });
<FieldGroup>
<Controller
name="title"
control={form.control}
rules={{ minLength: { value: 5, message: 'Bug title must be at least 5 characters.' } }}
render={({ field, fieldState }) => (
<Field invalid={fieldState.invalid}>
<FieldLabel nativeID="title-label" onPress={() => form.setFocus('title')}>
Bug Title
</FieldLabel>
<Input
ref={field.ref}
value={field.value}
onChangeText={field.onChange}
onBlur={field.onBlur}
aria-label="Bug Title"
aria-labelledby="title-label"
aria-invalid={fieldState.invalid}
/>
{fieldState.invalid && <FieldError errors={[fieldState.error]} />}
</Field>
)}
/>
<Button onPress={() => void form.handleSubmit(onSubmit)()}>
<Text>Submit</Text>
</Button>
</FieldGroup>;A schema library plugs in as on the web, through resolver and @hookform/resolvers.
Differences from upstream#
- A control takes
value,onChangeTextandonBlurfromfieldrather than{...field}: React Native's text field reports its text throughonChangeText, not a DOM change event. - There is no
<form>element to submit, so the submit button callsform.handleSubmit(onSubmit)()on its press, and a button outside the form needs noformattribute. - A label focuses its control through
form.setFocus(name), where the web'shtmlFordoes it: React Native has no label element to tie to a control's id. - Field marks its state with
invalidrather thandata-invalid, as the Field page says. - The demo validates with each
Controller'srules, where upstream's validates with a zod schema throughzodResolver, so that installing it adds no schema library and no@hookform/resolvers. A schema plugs in throughresolveras above.