Skip to Content
Zuri
Components

Input

A native text input with default, soft, underline and glass looks and an invalid state.

Live preview
Theme
Preview width

Use Input for single-line text. Always give it a name, either with Field or a Label. For multiple lines use Textarea.

Installation

pnpm dlx shadcn@latest add https://components.abdulqadirmsingi.com/r/input.json

Usage

import { Input } from "@/components/ui/input";

<Input type="email" autoComplete="email" name="email" />

Variants and states

Live preview
Theme
Preview width
  • default is an outlined field.
  • soft is a filled field with no visible border.
  • underline shows only a line underneath, for minimal and inline forms.
  • glass blurs whatever is behind it, so it needs a colourful or image backdrop to look right.

Want an icon, a prefix like +255, a unit like TZS, or a clear or show button beside the field? Use Input group.

Focus: with or without the halo

When a field has focus its border darkens and, by default, a soft grey glow appears around it. Some people prefer only the border: pass halo={false}. The border change still shows focus, so the field stays easy to see. Try the "No halo" field above.

<Input halo={false} />

The same halo prop is on Textarea, Input group and Phone input.

Sizes

Live preview
Theme
Preview width

Props

Input extends all native <input> props and spreads them onto the element, including ref (React 19).

Props
PropTypeDefaultDescription
variant"default" | "soft" | "underline" | "glass""default"Visual style.
size"sm" | "md" | "lg""md"Minimum heights of 32, 40 and 48 pixels. This replaces the native numeric size attribute.
halobooleantrueThe soft grey glow around a focused field. Set false to keep only the border change.
invalidboolean–Sets aria-invalid and a danger border, and makes the field shake once as it turns invalid. Field sets this for you.
typestring"text"Any native input type.
classNamestring–Merged with the built-in classes; yours win on conflicts.

Accessibility

  • It renders a native <input>: keyboard, autofill, mobile keyboards and form submission all work as the browser provides.
  • A visible focus ring appears on keyboard focus only.
  • A field that turns invalid shakes once (a short side-to-side tremor). It is turned off for people who ask for reduced motion, and the red border and your error text carry the message either way. To replay it after a second failed submit, set invalid to false and back to true.
  • Invalid state is exposed with aria-invalid, and the border change is not the only signal when used inside Field (the error text is too).
  • Use the right type, autoComplete and inputMode for the data; they matter for mobile users and password managers.

Tokens used

--background, --foreground, --muted-foreground, --control-border, --danger, --ring, --duration-base, --ease-out, and the glass variables.

Known limitations

  • No slots for icons or buttons: wrap it in Input group.
  • Glass text contrast has not been measured against worst-case backdrops.
  • It is a plain input. Controlled and uncontrolled use both work through native value / defaultValue.

Source

import { cva, type VariantProps } from "class-variance-authority";import type { ComponentProps } from "react";import { cn } from "@/lib/utils";const inputVariants = cva(  "w-full min-w-0 border text-foreground placeholder:text-muted-foreground transition-[border-color,background-color,box-shadow] duration-[var(--duration-base)] ease-[var(--ease-out)] focus-visible:border-ring focus-visible:outline-none disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-danger aria-[invalid=true]:focus-visible:border-danger aria-[invalid=true]:animate-[zuri-shake_var(--duration-slow)_var(--ease-out)] motion-reduce:animate-none motion-reduce:transition-none",  {    variants: {      // The soft grey glow around a focused field. Off for people who prefer just the border.      halo: {        true: "focus-visible:ring-4 focus-visible:ring-foreground/10",        false: "",      },      variant: {        default: "border-control-border bg-background",        // A filled field with no visible border, for calm forms.        soft: "border-transparent bg-muted",        // Only a line underneath, for minimal and inline forms.        underline: "border-0 border-b border-control-border bg-transparent",        glass: "zuri-glass",      },      size: {        sm: "min-h-8 rounded-md px-3 text-sm",        md: "min-h-10 rounded-md px-3 text-sm",        lg: "min-h-12 rounded-lg px-4 text-base",      },    },    // After the sizes, so the square corners and flush padding win over each size's own.    compoundVariants: [{ variant: "underline", class: "rounded-none px-0 focus-visible:ring-0" }],    defaultVariants: { variant: "default", size: "md", halo: true },  },);export interface InputProps  extends Omit<ComponentProps<"input">, "size">,    VariantProps<typeof inputVariants> {  /** Marks the value as invalid for assistive technology and styles the border. */  invalid?: boolean;}/** A native `<input>`. Pair it with a label (see Field) so it has an accessible name. */export function Input({  className,  variant,  size,  halo,  invalid,  type = "text",  ...props}: InputProps) {  return (    <input      type={type}      aria-invalid={invalid || props["aria-invalid"] || undefined}      className={cn(inputVariants({ variant, size, halo }), className)}      {...props}    />  );}export { inputVariants };

On this page