Floating Input
FreeA 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.
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
| Prop | Type | Default |
|---|---|---|
| label* | string | — |
| error | stringError message. Sets `aria-invalid` and is announced to screen readers. | — |
| hint | stringHelper text shown below the field. | — |
| trailing | React.ReactNodeContent 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.