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

Step 1: Install the following dependencies:

npm i @gluestack-ui/form-control

Step 2: Copy and paste the following code into your project.

import { Text, View } from "react-native"
import { styled } from "@gluestack-style/react"
import { createFormControl } from "@gluestack-ui/form-control"
import { AsForwarder } from "@gluestack-style/react"
const StyledRoot = styled(
View,
{
flexDirection: "column",
variants: {
size: {
sm: {
_labelText: {
props: { size: "sm" },
},
_labelAstrick: {
props: { size: "sm" },
},
_helperText: {
props: { size: "xs" },
},
_errorText: {
props: { size: "xs" },
},
},
md: {
_labelText: {
props: { size: "md" },
},
_labelAstrick: {
props: { size: "md" },
},
_helperText: {
props: { size: "sm" },
},
_errorText: {
props: { size: "sm" },
},
},
lg: {
_labelText: {
props: { size: "lg" },
},
_labelAstrick: {
props: { size: "lg" },
},
_helperText: {
props: { size: "md" },
},
_errorText: {
props: { size: "md" },
},
},
},
},
defaultProps: {
size: "md",
},
},
{
descendantStyle: [
"_labelText",
"_helperText",
"_errorText",
"_labelAstrick",
],
}
)
const StyledErrorIcon = styled(
AsForwarder,
{
color: "$error700",
fill: "none",
variants: {
size: {
"2xs": {
h: "$3",
w: "$3",
props: {
// @ts-ignore
size: 12,
},
},
xs: {
h: "$3.5",
w: "$3.5",
props: {
//@ts-ignore
size: 14,
},
},
sm: {
h: "$4",
w: "$4",
props: {
//@ts-ignore
size: 16,
},
},
md: {
h: "$4.5",
w: "$4.5",
props: {
//@ts-ignore
size: 18,
},
},
lg: {
h: "$5",
w: "$5",
props: {
//@ts-ignore
size: 20,
},
},
xl: {
h: "$6",
w: "$6",
props: {
//@ts-ignore
size: 24,
},
},
},
},
props: {
size: "md",
},
},
{
resolveProps: ["stroke", "fill"],
},
{
propertyTokenMap: {
stroke: "colors",
fill: "colors",
},
}
)
const StyledFormControlError = styled(View, {
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center",
mt: "$1",
gap: "$1",
})
// const StyeldFormControlErrorIcon = styled(StyledIcon, {
// color: '$error700',
// props: {
// size: 'sm',
// },
// });
const StyledFormControlErrorText = styled(
Text,
{
color: "$error700",
},
{ ancestorStyle: ["_errorText"] }
)
const StyledFormControlHelper = styled(View, {
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center",
mt: "$1",
})
const StyledFormControlHelperText = styled(
Text,
{
props: {
size: "xs",
},
color: "$text500",
},
{ ancestorStyle: ["_helperText"] }
)
const StyledFormControlLabel = styled(
View,
{
flexDirection: "row",
justifyContent: "flex-start",
alignItems: "center",
mb: "$1",
},
{ descendantStyle: ["_labelText"] }
)
const StyledFormControlLabelText = styled(Text, {
fontWeight: "$medium",
color: "$text900",
})
const StyledLabelAstrick = styled(Text, {}, {
componentName: "FormControlErrorText",
ancestorStyle: ["_labelAstrick"],
} as const)
export const FormControl = createFormControl({
Root: StyledRoot,
Error: StyledFormControlError,
ErrorText: StyledFormControlErrorText,
ErrorIcon: StyledErrorIcon,
Label: StyledFormControlLabel,
LabelText: StyledFormControlLabelText,
LabelAstrick: StyledLabelAstrick,
Helper: StyledFormControlHelper,
HelperText: StyledFormControlHelperText,
})
export const FormControlError = FormControl.Error
export const FormControlErrorText = FormControl.Error.Text
export const FormControlErrorIcon = FormControl.Error.Icon
export const FormControlLabel = FormControl.Label
export const FormControlLabelText = FormControl.Label.Text
export const FormControlLabelAstrick = FormControl.Label.Astrick
export const FormControlHelper = FormControl.Helper
export const FormControlHelperText = FormControl.Helper.Text

Step 3: Update the import paths to match your project setup.

API Reference

To use this component in your project, include the following import statement in your file.
import { FormControl } from '@/components/ui/FormControl';
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