Input
A single-line text input, used on its own or as the control inside a TextField.
Usage
import {Input} from "@peakui/react";A standalone Input has no visible label, so give it an aria-label. For a labelled field with a description and validation, compose it inside a TextField.
Examples
Variants
Use primary on the page background and secondary on a surface such as a card.
Types
Controlled
Full Width
Disabled State
A standalone Input is a native input and takes disabled. Inside a TextField, set isDisabled on the field instead.
Customization
Tailwind CSS
<Input aria-label="Search" className="rounded-full px-4" placeholder="Search" />Global CSS
@layer components {
.input {
--input-radius: var(--radius-lg);
}
.input--secondary {
--input-bg: var(--color-surface-secondary);
}
}Styling Reference
CSS Classes
The Input component uses these CSS classes (view source styles):
.input- Base input styles.input--primary- Primary variant.input--secondary- Secondary variant.input--full-width- Stretches to the container's width
Slots
[data-slot="input"]
CSS Variables
| Variable | Purpose |
|---|---|
--input-bg | Background color |
--input-bg-hover | Background color when hovered |
--input-bg-focus | Background color when focused |
--input-fg | Text color |
--input-placeholder | Placeholder color |
--input-border | Border color |
--input-border-hover | Border color when hovered |
--input-border-focus | Border color when focused |
--input-radius | Corner radius |
--input-shadow | Box shadow |
Interactive States
- Hover:
:hoveror[data-hovered] - Focus:
:focusor[data-focused] - Invalid:
[data-invalid]or[aria-invalid="true"] - Disabled:
:disabled,[data-disabled]or[aria-disabled="true"]
API Reference
Input
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'secondary' | 'primary' | Surface style. Inside a TextField it defaults to the field's variant |
fullWidth | boolean | false | Whether the input takes the full width of its container |
type | string | 'text' | The native input type |
value | string | - | The controlled value |
defaultValue | string | - | The initial value when uncontrolled |
placeholder | string | - | Placeholder text |
disabled | boolean | false | Whether the input is disabled |
onChange | (e: React.ChangeEvent<HTMLInputElement>) => void | - | Handler called when the value changes |
className | string | (values: InputRenderProps) => string | - | Additional classes, or a function of the input's state |
render | DOMRenderFunction<'input', InputRenderProps> | - | Replaces the rendered <input> with your own element |
Every other attribute of an <input> is accepted.
Render Props
When className is a function, it receives:
| Prop | Type | Description |
|---|---|---|
isHovered | boolean | Whether the input is hovered |
isFocused | boolean | Whether the input is focused |
isFocusVisible | boolean | Whether the input is focused by keyboard |
isDisabled | boolean | Whether the input is disabled |
isInvalid | boolean | Whether the input is invalid |