Skip to content
GitHub

Forms

A guide to building forms with Shark UI components.

Shark UI builds on Ark UI's Field and Fieldset components for integrating with native form element or popular form libraries like React Hook Form and TanStack Form.

Form Libraries

For detailed guides with examples, validation, and field-type-specific patterns, see the linked pages above.

Field Context

Form components in Shark UI automatically integrate with Field through context. When nested inside a Field, they inherit disabled, invalid, required, and readOnly states automatically.

Accessible Labels

When building accessible forms, you need to ensure that they are properly labeled and described.

  • FieldHelper: Used to provide additional instructions about the input.
  • FieldLabel: Used to provide an accessible label for the input.

These components are automatically linked to the input element via the aria-describedby attribute.

Best practice: Make sure that labels are visible (and not just used as placeholders) for screen readers to read them.

Error Handling and Validation

When the input is invalid, you can use the FieldError component to provide an error message for the input, and pass the invalid prop to the Field component.

Best practice: Make sure to provide clear, specific error messages that are easy to understand and fix.

Required Fields

To indicate that a field is required, you can pass the required prop to the Field component.

Optionally, you can use the <FieldRequiredIndicator /> to indicate that the field is required.

Fieldset Context

When you have multiple fields in a form or a component that renders multiple input elements, you can use the FieldSet component to group them together.

Common use cases: checkbox group, radio group, input + select composition, etc.

Checkbox Group

Radio Group