LabelNew

Text component for labeling form fields and other UI elements with support for required indicators and validation states.

Import

import { Label } from 'heroui-native';

Anatomy

<Label>
  <Label.Text>...</Label.Text>
</Label>
  • Label: Root container that manages label state and provides context to child components. When string children are provided, automatically renders as Label.Text. Supports disabled, required, and invalid states.
  • Label.Text: Text content of the label. Displays the label text and automatically shows an asterisk when the label is required. Changes color when invalid or disabled.

Usage

Basic Usage

Display a label with text content. String children are automatically rendered as Label.Text.

<Label>Username</Label>

With Form Fields

Use Label with form fields to provide accessible labels.

<TextField>
  <Label>Username</Label>
  <TextField.Input placeholder="Choose a username" />
</TextField>

Required Fields

Show an asterisk indicator for required fields using the isRequired prop.

<TextField>
  <Label isRequired>Password</Label>
  <TextField.Input placeholder="Create a password" secureTextEntry />
</TextField>

Invalid State

Display labels in an invalid state to indicate validation errors.

<TextField isInvalid>
  <Label isInvalid>Confirm password</Label>
  <TextField.Input
    placeholder="Confirm your password"
    secureTextEntry
    value="different"
    editable={false}
  />
  <TextField.ErrorMessage>Passwords do not match</TextField.ErrorMessage>
</TextField>

Disabled State

Disable labels to indicate non-interactive fields.

<TextField isDisabled>
  <Label>Subscription plan</Label>
  <TextField.Input value="Premium" />
</TextField>

Custom Layout

Use compound components for custom label layouts.

<Label>
  <Label.Text>Custom label</Label.Text>
</Label>

Custom Styling

Apply custom styles using className, classNames, or styles props.

<Label className="mb-2">
  <Label.Text
    className="text-lg"
    classNames={{
      text: "font-bold",
      asterisk: "text-danger"
    }}
  >
    Custom styled label
  </Label.Text>
</Label>

Example

import { Label, TextField } from 'heroui-native';
import { View } from 'react-native';

export default function LabelExample() {
  return (
    <View className="flex-1 justify-center px-5 gap-8">
      <TextField>
        <Label>Username</Label>
        <TextField.Input placeholder="Choose a username" />
      </TextField>
      <TextField>
        <Label isRequired>Password</Label>
        <TextField.Input placeholder="Create a password" secureTextEntry />
      </TextField>
      <TextField isInvalid>
        <Label isInvalid>Confirm password</Label>
        <TextField.Input
          placeholder="Confirm your password"
          secureTextEntry
          value="different"
          editable={false}
        />
        <TextField.ErrorMessage>Passwords do not match</TextField.ErrorMessage>
      </TextField>
      <TextField isDisabled>
        <Label>Subscription plan</Label>
        <TextField.Input value="Premium" />
      </TextField>
    </View>
  );
}

You can find more examples in the GitHub repository.

API Reference

Label

proptypedefaultdescription
childrenReact.ReactNode-Label content. When string is provided, automatically renders as Label.Text. Otherwise renders children as-is
isRequiredbooleanfalseWhether the label is required. Shows asterisk indicator when true
isInvalidbooleanfalseWhether the label is in an invalid state. Changes text color to danger
isDisabledbooleanfalseWhether the label is disabled. Applies disabled styling and prevents interaction
classNamestring-Additional CSS classes to apply
animation"disable-all" | undefinedundefinedAnimation configuration. Use "disable-all" to disable all animations including children
...PressablePropsPressableProps-All standard React Native Pressable props are supported

Label.Text

proptypedefaultdescription
childrenReact.ReactNode-Label text content
classNamestring-Additional CSS classes to apply to the text element
classNamesElementSlots<LabelSlots>-Additional CSS classes for different parts of the label
stylesPartial<Record<LabelSlots, TextStyle>>-Styles for different parts of the label
nativeIDstring-Native ID for accessibility. Used to link label to form fields via aria-labelledby
...TextPropsTextProps-All standard React Native Text props are supported

ElementSlots<LabelSlots>

proptypedescription
textstringCSS classes for the label text
asteriskstringCSS classes for the asterisk

On this page