- 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 { TextField } from '@/ui/forms/TextField';
export function TextFieldDemo() {
return (
<div className="flex flex-col gap-16">
<TextField
label="Email Address"
description="Enter your email address"
placeholder="you@example.com"
className="max-w-sm"
/>
<TextField
label="Disabled"
description="This field is disabled"
placeholder="Disabled input"
disabled
className="max-w-sm"
/>
<TextField
label="With Icon"
description="This field has an icon"
placeholder="Search..."
icon="PeopleSingle"
className="max-w-sm"
validationStatus="success"
/>
<TextField
label="Error"
description="This field has an error message"
placeholder="Enter your text"
className="max-w-sm"
validationStatus="error"
errorMessage="This is an error message"
/>
<TextField
label="Success"
description="This field has a success message"
placeholder="Enter your text"
className="max-w-sm"
validationStatus="success"
/>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/text-field.json
Usage
'use client';
import { useState } from 'react';
import { TextField } from '@/docs/lib/ui/forms/text-field';
export function Component() {
const [email, setEmail] = useState('');
return (
<TextField
label="Email Address"
description="We'll never share your email"
placeholder="you@example.com"
value={email}
onChange={(name, value) => setEmail(value)}
icon="MailDefault"
required
validationStatus="default"
className="max-w-sm"
/>
);
}API Reference
TextField
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | undefined | The label text displayed above the input field |
description | string | undefined | Helper text displayed below the label to provide additional context |
id | string | auto-generated | The HTML id attribute for the input element. Auto-generated if not provided |
name | string | id | The name attribute for the input. Defaults to the id value |
value | Value | undefined | The controlled value of the input field. Supports generic type parameter |
onChange | (name: string, value: Value) => void | undefined | Callback fired when the input value changes. Receives the field name and new value |
disabled | boolean | false | If true, disables the input field and applies disabled styling (grey background) |
required | boolean | false | If true, marks the field as required and displays a red asterisk next to the label |
hideRequiredStar | boolean | false | If true, hides the required asterisk even when required is true |
validationStatus | "default" | "error" | "success" | "default" | The validation state of the field. Changes border color and displays validation icons |
errorMessage | string | undefined | Error message displayed below the field when validationStatus is "error" |
icon | IconicNames | undefined | Optional icon displayed on the left side of the input field |
iconType | IconicTypes | undefined | The icon type variant for validation icons (error/success indicators) |
formatter | (value: Value) => Value | undefined | Optional function to format/transform the input value before updating state |
dataTestId | string | "TextField" | Custom test ID for testing purposes |
className | string | undefined | Additional CSS classes to apply to the FormControl container |
hasDropdown | boolean | false | If true, displays a dropdown icon on the right side of the input field |
clear | string | "" | Text for the clear button aria-label (and controls whether such a button exists) |
iconFirst | boolean | true | If true, displays the icon on the left side of the input field |
...rest | InputHTMLAttributes<HTMLInputElement> | - | All standard HTML input attributes (placeholder, type, autoComplete, etc.) are supported |
Notes
-
FormControl Integration: TextField is built on top of FormControl, providing consistent label, description, and error message layout across form fields
-
Generic Value Type: Supports generic type parameter for type-safe value handling. By default uses
string, but can be customized withTextField<number>or other types -
Automatic State Management: Uses internal
useValuehook to manage state. Can be used as controlled or uncontrolled component -
Validation States: Three validation states available:
default: Standard grey border with black focuserror: Red border with cross icon on the rightsuccess: Green border with checkmark icon on the right
-
Validation Icons: Error (cross) and success (checkmark) icons automatically appear on the right side when validation status changes
-
Icon Support: Optional icon can be displayed on the left side of the input using the
iconprop with any IconicNames value -
Custom Formatter: The
formatterprop allows transformation of input values before they're passed to onChange (e.g., uppercase conversion, number formatting) -
Disabled State: When disabled, the input displays grey background (
bg-pearl) and grey text, and user interaction is blocked -
Rounded Pill Design: Input has rounded pill styling (
rounded-pill) with consistent padding -
Dynamic Padding: Automatically adjusts padding based on presence of icons:
- Left padding increases when icon is present
- Right padding increases when validation icons are shown
-
Automatic ID Generation: If no id is provided, React's useId hook generates a unique ID for accessibility
-
Accessibility: Input includes aria-label attribute set to the field name for screen reader support
-
Client Component: This is a client component (uses React hooks) and must be used in client-side contexts
-
Data Attributes: Includes
data-name="TextField"for testing and debugging purposes