Skip to content

React Contact Form

ContactForm is a React contact form block with name, email and message fields on glass, inline validation, a button that glows while sending and a success seal. It works with a plain onSubmit or react-hook-form.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/contact-form.json

Contact

Talk to us

Questions, feedback or a project in mind. We reply within one working day.

Plain onSubmit

Submit it empty to see the messages and the focus move, then fill it in. onSubmit returns a promise, so the button shows its loading light until it settles; throw from it to show an error under the form.

Contact

Talk to us

Questions, feedback or a project in mind. We reply within one working day.

Files to copy

11 folders · 16 files · 4 packages
From theme/src/
  • blocks/{contact-form.tsx, icons.tsx}
  • components/button/
  • components/glass-card/
  • components/input/
  • components/spinner/
  • components/status-icons/
  • components/textarea/
  • hooks/{use-controllable.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}
  • motion/{gate.ts, light-follower.ts, tokens.ts}
  • lib/{cn.ts, field-size.ts, form.ts, heading.ts, state-light.tsx, warn-once.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/contact-form.jsonRegistry item: contact-form. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

With react-hook-form

validate={false} turns the block's own checks off. fieldProps takes register(...) for each field, errors takes formState.errors, and status follows isSubmitting and isSubmitSuccessful. The state light and the success seal work the same.

Write to us

Props

PropTypeDefaultDescription
onSubmit((values: ContactFormValues) => void | Promise<void>)NoneCalled with the trimmed values once they pass validation ((values: ContactFormValues) => void | Promise<void>). Return a promise to show the loading state; throw to show an error under the form.
validatebooleantrueRun the block's own checks on submit (boolean). Pass false when a form library validates for you, and feed its messages back through errors.
errorsPartial<Record<"form" | ContactField, string>>NoneError messages from outside (Partial<Record<ContactField | "form", string>>), for example from react-hook-form's formState.errors. They win over the block's own.
fieldPropsPartial<Record<ContactField, ClassAttributes<HTMLInputElement> & InputHTMLAttributes<HTMLInputElement> & ClassAttributes<HTMLTextAreaElement> & TextareaHTMLAttributes<HTMLTextAreaElement>>>NoneExtra props for each control (Partial<Record<ContactField, ComponentProps<"input"> | ComponentProps<"textarea">>>), so {...register("email")} from react-hook-form can be handed over.
statusContactFormStatusNoneControls the status (ContactFormStatus), for when a form library or your own state knows it. Leave it out to let the block track it.
defaultValuesPartial<ContactFormValues>NoneThe values the fields start with (Partial<ContactFormValues>).
minMessageLengthnumber10The shortest message accepted by the block's own check (number).
maxMessageLengthnumber1000The longest message (number); a character counter is shown.
onReset(() => void)NoneCalled when the success view's button returns to an empty form (() => void), e.g. to reset your form library.
eyebrowReactNodeNoneShows a small label above the title (ReactNode).
titleReactNodeNoneSets the heading (ReactNode).
descriptionReactNodeNoneSets the line under the heading (ReactNode).
asideReactNodeNoneContact details or a map beside the form on a wide block (ReactNode).
headingLevelHeadingLevelOption2Level of the heading (1 to 6); "none" renders plain text, no heading.
labelsPartial<ContactFormLabels>defaultContactFormLabelsEvery other string, for translation: labels={{ name: "…" }}; omitted keys keep the English of defaultContactFormLabels. All 14 keys of ContactFormLabels are listed in the key table under the props table.
classNamestringNoneAdds extra classes to the outer element (string).
ContactFormLabels keys and English defaults (14)
Pass any key in labels; the rest keep the defaults of defaultContactFormLabels.
KeyEnglish default
nameName
namePlaceholderYour name
emailEmail
emailPlaceholderyou@example.com
messageMessage
messagePlaceholderHow can we help?
submitSend message
nameRequiredEnter your name.
invalidEmailEnter a valid email address.
shortMessage(min) => `Write at least ${min} characters.`
genericErrorSomething went wrong. Try again.
successTitleMessage sent
successTextThanks for writing. We usually reply within one working day.
anotherSend another message

Keyboard

KeysAction
TabName, email, message, then the send button.
EnterIn a single-line field: submit the form.
Tab after successFocus has moved to the success message; Tab reaches 'Send another message'.

Accessibility

  • A real <form> with noValidate. Errors are visible text linked with aria-describedby; a failed check moves focus to the first invalid field.
  • The success view is a status region and receives focus; the outcome is always text, never light alone.
  • The form and the success view share one grid cell, so the card never changes height.
  • The button glows while sending (state light) and the seal's check is drawn once. Reduced motion: the seal fades in and the check appears at once.

All exports on this page

  • ContactForm — A contact form on glass: name, email and a message with inline validation, a loading button and a success seal that lights green.
  • defaultContactFormLabels — The English ContactFormLabels used when labels is omitted; a partial labels prop is merged over it.

When to use the contact form

  • Use ContactForm on a contact or support page, with onSubmit(values) returning a promise so the button shows its loading light and a thrown error appears under the form.
  • Use it beside react-hook-form by passing validate={false}, fieldProps from register(...), errors from formState.errors and a status derived from isSubmitting and isSubmitSuccessful.
  • Use the aside slot for an address, hours or a map beside the form on a wide block, and eyebrow, title and description for the heading.
  • Skip it for a long multi-step form; the Stepper and Field components are built for that, while ContactForm is three fields and a message.
  • Pair it with FaqSection above it and SiteFooter below, and send the message from your server with a spam check rather than from the browser alone.

Frequently asked questions

20 blocks pages in all: browse them on All blocks.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .