Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Input for Astro

Native Astro inputs with shared focus, error, and disabled styles.

Installation

bunx --bun shadcn@latest add @gnostic/input
npx shadcn@latest add @gnostic/input
pnpm dlx shadcn@latest add @gnostic/input

Component classes: Default Gnostic.

Complete the Installation guide first. Then copy the component files below.

No extra packages are required.

Copy the files

src/components/ui/input/index.ts
export { default as Input } from "./input.astro"
src/components/ui/input/input.astro
---
import type { HTMLAttributes } from "astro/types"

import { cn } from "cn"

type Props = HTMLAttributes<"input">

const {
  class: className,
  "data-slot": dataSlot = "input",
  ...props
} = Astro.props
---

<input data-slot={dataSlot} class={cn("font-sans border-input bg-background text-foreground ring-ring/24 placeholder:text-muted-foreground/72 dark:bg-input/32 focus-visible:border-ring aria-invalid:border-destructive/36 focus-visible:aria-invalid:border-destructive/64 focus-visible:aria-invalid:ring-destructive/16 dark:aria-invalid:ring-destructive/24 file:text-foreground h-9 w-full min-w-0 rounded-lg border px-[calc(--spacing(3)-1px)] text-base shadow-xs/5 transition-shadow outline-none not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_1px_--theme(--color-black/4%)] file:me-3 file:border-0 file:bg-transparent file:text-sm file:font-medium autofill:[-webkit-text-fill-color:var(--foreground)] focus-visible:shadow-none focus-visible:ring-[3px] disabled:pointer-events-none disabled:opacity-64 sm:h-8 sm:text-sm dark:not-disabled:not-focus-visible:not-aria-invalid:inset-shadow-[0_-1px_--theme(--color-white/6%)]", className)} {...props} />

Usage

import { Input } from "@/components/ui/input"
<Input />

Examples

Basic

Disabled

Invalid

File

Notes

  • Use Input for single-line text-like controls such as email, password, and phone fields.
  • Pair it with Label for simple forms, or use Field when you also need descriptions, validation, or grouped layouts.
  • Use Floating Input when the label sits in the field and floats to the border.
  • Set aria-invalid when the control should display an invalid state.

API Reference

Read the installed source for the complete prop types.

When to use Input

Set the native input type, name, and ID for the data you need. Link a visible Label with for. Use autocomplete values that match the field purpose and keep placeholders as examples rather than labels.

Keyboard and behavior

This is a native input, so browser editing, form submission, required checks, and disabled behavior remain available. aria-invalid applies the error style but does not validate the value. Link error text with aria-describedby.

Theme and layout

The single input carries its own border and inset shadow. It does not add the React wrapper used by Coss. Native size retains its HTML meaning; use classes for visual width. Check autofill and file controls in the browsers you support.