Skip to Content
Neshel-UI
Components

Input

A native text input with field sizes and an invalid state.

Server-compatible (no "use client")

Purpose

Input is a styled native <input>. Every native attribute works: type, name, autoComplete, required, pattern, list, …

Import

import.tsx
import { Input } from "@neshel-ui/components";

Usage

Preview: input-states
Preview theme

Use letters and numbers only.

input-states.tsx
import { Input, Label } from "@neshel-ui/components";
import { Inline, Stack } from "@neshel-ui/layout";
import { Caption } from "@neshel-ui/typography";

export default function InputStates() {
  return (
    <Stack space="5" className="max-w-sm">
      <Stack space="2">
        <Label htmlFor="demo-email" required>
          Email
        </Label>
        <Input
          id="demo-email"
          type="email"
          autoComplete="email"
          placeholder="ana@example.com"
          required
        />
      </Stack>
      <Stack space="2">
        <Label htmlFor="demo-username">Username</Label>
        <Input
          id="demo-username"
          invalid
          aria-describedby="demo-username-error"
          defaultValue="ana!"
        />
        <Caption id="demo-username-error" tone="destructive">
          Use letters and numbers only.
        </Caption>
      </Stack>
      <Inline space="2">
        <Input aria-label="Small field" uiSize="sm" placeholder="sm" />
        <Input aria-label="Large field" uiSize="lg" placeholder="lg" />
      </Inline>
      <Input aria-label="Disabled field" disabled defaultValue="Disabled" />
    </Stack>
  );
}

API

InputProps

InputProps
PropTypeDefaultDescription
invalidboolean—Sets aria-invalid="true" unless aria-invalid is given explicitly.
refRef<HTMLInputElement>——
uiSizeFieldSize—Styling size; the native numeric size attribute keeps its HTML meaning.

Also accepts the props of: React DOM attributes.

  • uiSize (sm md lg) is the visual size; the native numeric size attribute keeps its HTML meaning.
  • invalid sets aria-invalid="true" unless you pass aria-invalid yourself.

Controlled and uncontrolled

React's native rules apply: defaultValue (uncontrolled) or value + onChange (controlled).

Accessibility

Always label the input (<Label htmlFor>, aria-label or aria-labelledby). Reference hints and errors with aria-describedby. Use the right type and autoComplete so browsers and assistive technology can help users.

Common mistakes

  • Using size="lg" for styling: that sets the native character width. Use uiSize.
  • A placeholder instead of a label.

See Forms.

Edit on GitHub

On this page