FormControl

By using FormControl, developers can provide important context to form elements. This context can include whether the element is invalid, disabled, or required.
Installation
API Reference
Spec Doc
This is an illustration of FormControl component.
size
isDisabled
isInvalid
isReadOnly
isRequired
<Box h="$32" w="$72">
<FormControl
size="md"
isDisabled={false}
isInvalid={false}
isReadOnly={false}
isRequired={false}
>
<FormControlLabel mb="$1">
<FormControlLabelText>Password</FormControlLabelText>
</FormControlLabel>
<Input>
<InputField type="password" defaultValue="12345" placeholder="password" />
</Input>
<FormControlHelper>
<FormControlHelperText>
Must be at least 6 characters.
</FormControlHelperText>
</FormControlHelper>
<FormControlError>
<FormControlErrorIcon as={AlertCircleIcon} />
<FormControlErrorText>
At least 6 characters are required.
</FormControlErrorText>
</FormControlError>
</FormControl>
</Box>

Installation

Run the following command:

npx gluestack-ui add form-control

API Reference

To use this component in your project, include the following import statement in your file.
import { FormControl } from "@/components/ui/form-control"
export default () => (
<FormControl>
<FormControlLabel>
<FormControlLabelText />
</FormControlLabel>
<FormControlHelper>
<FormControlHelperText />
</FormControlHelper>
<FormControlError>
<FormControlErrorIcon />
<FormControlErrorText />
</FormControlError>
</FormControl>
)

Component Props

This section provides a comprehensive reference list for the component props, detailing descriptions, properties, types, and default behavior for easy project integration.

FormControl

It inherits all the properties of React Native's View component.
Prop
Type
Default
Description
size
'sm' | 'md' | 'lg'
'sm'
Sets the size of the FormControl children.
isInvalid
bool
false
When true, invalid state.
isRequired
bool
false
If true, astrick gets activated.
isDisabled
bool
false
Disabled state true.
isReadOnly
bool
false
To manually set read-only state.
isDisabled
bool
false
To manually set disable to the FormControl.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_labelText
Prop to style FormControlLabelText Component
_helperText
Prop to style FormControlHelperText Component
_errorText
Prop to style FormControlErrorText Component
_labelAstrick
Prop to style FormControlLabelAstrick Component

FormControlLabel

It inherits all the properties of React Native's View component.
Descendants Styling Props Props to style child components.
Sx Prop
Description
_labelText
Prop to style FormControlLabelText Component

FormControlLabelText

It inherits all the properties of React Native's Text component.

FormControlHelper

It inherits all the properties of React Native's View component.

FormControlHelperText

It inherits all the properties of React Native's Text component.

FormControlError

It inherits all the properties of React Native's View component.

FormControlErrorIcon

It inherits all the properties of gluestack Style's AsForwarder component.

FormControlErrorText

It inherits all the properties of React Native's Text component.

Features

  • Keyboard support for actions.
  • Support for hover, focus and active states.
  • Option to add your styles or use the default styles.

Props

FormControl component is created using View component from react-native. It extends all the props supported by React Native View, utility props and the props mentioned below.

FormControl

Name
Value
Default
size
sm | md | lg
md

Examples

The Examples section provides visual representations of the different variants of the component, allowing you to quickly and easily determine which one best fits your needs. Simply copy the code and integrate it into your project.

Form Control with Input

The Input Component can be incorporated within the FormControl.
<FormControl minWidth="$80">
<FormControlLabel>
<FormControlLabelText>Name</FormControlLabelText>
</FormControlLabel>
<Input>
<InputField />
</Input>
<FormControlHelper>
<FormControlHelperText>
What would you like people to call you?
</FormControlHelperText>
</FormControlHelper>
</FormControl>

Form Control with Radio

The Radio Component can be incorporated within the FormControl.
<FormControl>
<FormControlLabel>
<FormControlLabelText>Favourite fruit</FormControlLabelText>
</FormControlLabel>