Field

A controlled form field component.

Field is a complete functional form control that renders a specific field type based on the data type used. It handles the field state, renders a label, the input, help text, error messages

Import#

  • Field: The wrapper component that controls context, state and manages rendering field types.
import { Field } from '@saas-ui/react'

Usage#

The Field is a controlled component and should aways be wrapped with Form, as it depends on the form context.

Build in field types#

Build in field types are text, textarea, number, password, select, native-select, radio, checkbox, switch, pin. Any other type will fallback to a regular HTML input element. Eg: email will render as a InputField with the type set to email.

Text field#

Live edit

Textarea field#

Live edit

Number field#

The number field value is always a string, you have to parse it yourself.

Live edit

Password field#

Live edit

Select field#

Live edit

Native Select field#

On mobile devices interaction can be improved by using the native select.

Live edit

Radio field#

Live edit

Checkbox field#

Live edit

Switch field#

Live edit

Pin field#

The pin length defaults to 4.

Live edit

Advanced#

Creating your own fields.#

// form.tsx
import { createForm, createField } from '@saas-ui/react'
import ReactSelect from 'react-select'
const ReactSelectField = createField(ReactSelect, {
isControlled: true,
})
export const Form = createForm({
fields: {
'react-select': ReactSelectField,
},
})

Overriding default fields.#

You can override any of the build in types by registering a field on the corresponding key.

// form.tsx
import { createForm, createField } from '@saas-ui/react'
import ReactSelect from 'react-select'
const ReactSelectField = createField(ReactSelect, {
isControlled: true,
})
export const Form = createForm({
fields: {
select: ReactSelectField,
},
})

Was this helpful?