Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Floating Input

Free

A text field whose label floats up on focus or when filled.

Installation

pnpm dlx shadcn@latest add @viewport/floating-input

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above.

floating-input-demo.tsx
import { FloatingInput } from "@/components/viewport/floating-input";

export default function FloatingInputDemo() {
  return (
    <form className="flex w-full max-w-sm flex-col gap-4">
      <FloatingInput label="Full name" name="name" autoComplete="name" />
      <FloatingInput label="Work email" name="email" type="email" autoComplete="email" hint="We only email you about your account." />
      <FloatingInput label="Team URL" name="url" defaultValue="truffle ui" error="Use letters, numbers and dashes only." />
    </form>
  );
}

Props

PropTypeDefault
label*string—
errorstring

Error message. Sets `aria-invalid` and is announced to screen readers.

—
hintstring

Helper text shown below the field.

—
trailingReact.ReactNode

Content pinned inside the field's right edge, such as a show-password button.

—

Accessibility

  • A real label tied to the input.
  • Errors set aria-invalid and are announced with role=alert.
  • Pure CSS, so it works before hydration.