- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- ChatButton
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- FormCheckbox
- Form Control
- Form Label
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Select
- SidebarLayout
- Spinner
- Switch
- Tabs
- Tag
- TextField
- ValidationMessage
'use client';
import { FormLabel } from '@/ui/forms/FormLabel';
export function FormLabelDemo() {
return (
<FormLabel id="email" required description="We'll never share your email" layout="horizontal">
Email Address
</FormLabel>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/form-label.json
Usage
import { FormLabel } from '@/docs/lib/ui/forms/form-label';
export function Component() {
return (
<FormLabel id="email" required description="Optional helper text" layout="horizontal">
Email Address
</FormLabel>
);
}API Reference
FormLabel
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined | The ID of the form field this label is associated with (sets htmlFor) |
children | ReactNode | undefined | The label text content |
description | string | undefined | Optional descriptive text displayed alongside the label |
layout | "horizontal" | "horizontal-${string}" | "vertical" | "horizontal" | Controls the label's layout and spacing. Use "horizontal-no-padding" to remove default padding |
required | boolean | undefined | Whether the field is required. Shows an asterisk (*) when true |
hideRequiredStar | boolean | !required | Hides the required asterisk even when required is true |
className | string | undefined | Additional CSS classes to apply to the label element |
| ...rest | LabelHTMLAttributes<HTMLLabelElement> | - | All standard HTML label attributes are supported |
Notes
-
Layout Options: The component supports flexible layout modes:
"horizontal": Default horizontal layout with left padding (ps-20) and centered items"horizontal-no-padding": Horizontal layout without left padding"vertical": Stacks label and description vertically with left alignment- Custom horizontal variants: Any string starting with
"horizontal-"follows horizontal layout rules
-
Required Indicator: When
requiredis true, an asterisk (*) is automatically displayed after the label text. UsehideRequiredStarto hide it if needed. By default,hideRequiredStaris!required, meaning the star is only shown when the field is required. -
Description Text: Optional helper text can be displayed alongside the label using the
descriptionprop. It appears with lighter styling (text-grey,font-normal,text-b4) and left margin (ms-12). -
Semantic HTML: Renders as a native
<label>element with properhtmlForattribute linking to the form field via theidprop. -
Accessibility: The component ensures proper form field association through the
htmlForattribute, improving accessibility for screen readers and enabling click-to-focus behavior. -
Styling: The component applies base styles including semibold font weight, black text color, and flexible layout classes. Custom styles can be added via the
classNameprop. -
Data Attributes: Includes
data-name="InputLabel"for testing and debugging purposes. -
Standard Attributes: All standard HTML label attributes (like
onClick,onMouseEnter, etc.) are supported through prop spreading.