PeakUI

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

VariablePurpose
--input-bgBackground color
--input-bg-hoverBackground color when hovered
--input-bg-focusBackground color when focused
--input-fgText color
--input-placeholderPlaceholder color
--input-borderBorder color
--input-border-hoverBorder color when hovered
--input-border-focusBorder color when focused
--input-radiusCorner radius
--input-shadowBox shadow

Interactive States

  • Hover: :hover or [data-hovered]
  • Focus: :focus or [data-focused]
  • Invalid: [data-invalid] or [aria-invalid="true"]
  • Disabled: :disabled, [data-disabled] or [aria-disabled="true"]

API Reference

Input

PropTypeDefaultDescription
variant'primary' | 'secondary''primary'Surface style. Inside a TextField it defaults to the field's variant
fullWidthbooleanfalseWhether the input takes the full width of its container
typestring'text'The native input type
valuestring-The controlled value
defaultValuestring-The initial value when uncontrolled
placeholderstring-Placeholder text
disabledbooleanfalseWhether the input is disabled
onChange(e: React.ChangeEvent<HTMLInputElement>) => void-Handler called when the value changes
classNamestring | (values: InputRenderProps) => string-Additional classes, or a function of the input's state
renderDOMRenderFunction<'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:

PropTypeDescription
isHoveredbooleanWhether the input is hovered
isFocusedbooleanWhether the input is focused
isFocusVisiblebooleanWhether the input is focused by keyboard
isDisabledbooleanWhether the input is disabled
isInvalidbooleanWhether the input is invalid

On this page