PeakUI

Label

A text label for a form control, with required, invalid and disabled states.

Usage

import {Label} from "@peakui/react";

Examples

In a TextField

Inside a TextField the label is linked to the input automatically, and it follows the field's required, invalid and disabled states. You do not pass the state props.

States

Outside a field nothing can pass the state down, so set it on the label.

Customization

Tailwind CSS

<Label className="text-xs tracking-wide uppercase">Email</Label>

Global CSS

@layer components {
  .label {
    @apply font-semibold;
  }
}

Styling Reference

CSS Classes

The Label component uses these CSS classes (view source styles):

  • .label - Base label styles
  • .label--required - Adds the required indicator
  • .label--invalid - Invalid state color
  • .label--disabled - Disabled state

Slots

  • [data-slot="label"]

Interactive States

Inside a field, the label is styled from the field root's attributes:

  • Required: [data-required] on the parent, or a [aria-required="true"] control inside a .textfield
  • Invalid: [data-invalid] or [aria-invalid="true"] on an ancestor
  • Disabled: [data-disabled] or [aria-disabled="true"] on an ancestor, or an ancestor <fieldset disabled>

API Reference

Label

PropTypeDefaultDescription
isRequiredbooleanfalseShows the required indicator. Not needed inside a TextField
isInvalidbooleanfalseApplies the invalid style. Not needed inside a TextField
isDisabledbooleanfalseApplies the disabled style. Not needed inside a TextField
htmlForstring-The id of the control the label describes. Set automatically inside a TextField
elementTypestring'label'The element to render
renderDOMRenderFunction<'label', undefined>-Replaces the rendered element with your own
childrenReact.ReactNode-The label text
classNamestring-Additional classes

Every other attribute of a <label> is accepted.

On this page