Input
The shadcn/ui Input with a hover state, softer focus ring, clear invalid state and on-theme autofill — plus five Motion blocks: floating label, password with strength meter, search, one-time code and a shimmering AI prompt field.
- Drop-in shadcn API
- Server Component friendly
- Motion blocks
- Autofill-safe
Type or paste 123456
"use client";
import * as React from "react";
import { OTPInput } from "@/components/dusk/input/otp-input";
export default function OTPInputDemo() {
const [code, setCode] = React.useState("");
const [status, setStatus] = React.useState<"idle" | "invalid" | "valid">("idle");
return (
<div className="flex flex-col items-center gap-3">
<OTPInput
value={code}
onValueChange={(v) => {
setCode(v);
setStatus("idle");
}}
onComplete={(v) => setStatus(v === "123456" ? "valid" : "invalid")}
invalid={status === "invalid"}
aria-label="Verification code"
/>
<p className="h-4 text-xs text-muted-foreground" aria-live="polite">
{status === "valid" ? "Verified ✓" : status === "invalid" ? "Wrong code — try 123456" : "Type or paste 123456"}
</p>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/input.json1. Copy the source into
components/ui/input.tsx.input.tsx import * as React from "react"; import { cn } from "@/lib/utils"; /** * DuskUI Input — a drop-in upgrade of the shadcn/ui Input. * * Same API as shadcn. Adds a subtle hover background, a clear focus ring, a clear * invalid state, dark-mode autofill without the browser's yellow fill, and * tidy file / search inputs. CSS only, so it works in Server Components. */ function Input({ className, type, ...props }: React.ComponentProps<"input">) { return ( <input type={type} data-slot="input" className={cn( "h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs outline-none md:text-sm dark:bg-input/30", "transition-[color,background-color,border-color,box-shadow] duration-150 ease-out motion-reduce:transition-none", "placeholder:text-muted-foreground placeholder:transition-opacity focus:placeholder:opacity-60", "selection:bg-primary selection:text-primary-foreground", "dark:hover:bg-input/40", "focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", "aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40", "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50", "read-only:bg-muted/40 read-only:focus-visible:ring-0", // Keep autofilled fields on-theme instead of the browser's yellow/blue fill. "autofill:shadow-[inset_0_0_0_1000px_var(--card)] autofill:[-webkit-text-fill-color:var(--foreground)]", "file:mr-3 file:inline-flex file:h-7 file:cursor-pointer file:rounded-sm file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground", "[&::-webkit-search-cancel-button]:appearance-none", className )} {...props} /> ); } export { Input };
Replaces components/ui/input.tsx with the same API. The base Input is CSS-only — no"use client" needed.
Usage
import { Input } from "@/components/ui/input"
export function Newsletter() {
return <Input type="email" placeholder="you@example.com" aria-label="Email" />
}Examples
Default
Hover to see the border warm up; focus for the soft ring.
import { Input } from "@/components/ui/input";
export default function InputBasicDemo() {
return <Input type="email" placeholder="you@example.com" className="max-w-sm" />;
}With label & hint
Always pair an input with a <label>, and link hints with aria-describedby.
Visible to everyone in your workspace.
import { Input } from "@/components/ui/input";
export default function InputWithLabelDemo() {
return (
<div className="grid w-full max-w-sm gap-2">
<label htmlFor="team-name" className="text-sm font-medium">
Team name
</label>
<Input id="team-name" placeholder="Acme Inc." aria-describedby="team-name-hint" />
<p id="team-name-hint" className="text-xs text-muted-foreground">
Visible to everyone in your workspace.
</p>
</div>
);
}Invalid
Set aria-invalid for the red state. The error message animates its height in and out so the form below doesn't jump.
Enter a valid email address.
"use client";
import * as React from "react";
import { AnimatePresence, motion } from "motion/react";
import { Input } from "@/components/ui/input";
export default function InputInvalidDemo() {
const [value, setValue] = React.useState("not-an-email");
const invalid = value.length > 0 && !/^\S+@\S+\.\S+$/.test(value);
return (
<div className="grid w-full max-w-sm gap-2">
<label htmlFor="email-check" className="text-sm font-medium">
Email
</label>
<Input
id="email-check"
value={value}
onChange={(e) => setValue(e.target.value)}
aria-invalid={invalid || undefined}
aria-describedby="email-check-error"
/>
<AnimatePresence initial={false}>
{invalid && (
<motion.p
id="email-check-error"
role="alert"
className="text-xs text-destructive"
initial={{ opacity: 0, height: 0, y: -4 }}
animate={{ opacity: 1, height: "auto", y: 0 }}
exit={{ opacity: 0, height: 0, y: -4 }}
transition={{ type: "spring", duration: 0.3, bounce: 0 }}
>
Enter a valid email address.
</motion.p>
)}
</AnimatePresence>
</div>
);
}Disabled, read-only & file
Each native state has its own styling, including a tidy file picker.
import { Input } from "@/components/ui/input";
export default function InputStatesDemo() {
return (
<div className="grid w-full max-w-sm gap-3">
<Input placeholder="Disabled" disabled />
<Input defaultValue="Read only" readOnly />
<Input type="file" />
</div>
);
}Blocks
Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.
OTP Input
A one-time-code field where the active ring glides between slots, digits fade in and a wrong code shakes. It's one real input under the hood, so paste, SMS autofill (autocomplete="one-time-code") and backspace just work.
Type or paste 123456
"use client";
import * as React from "react";
import { OTPInput } from "@/components/dusk/input/otp-input";
export default function OTPInputDemo() {
const [code, setCode] = React.useState("");
const [status, setStatus] = React.useState<"idle" | "invalid" | "valid">("idle");
return (
<div className="flex flex-col items-center gap-3">
<OTPInput
value={code}
onValueChange={(v) => {
setCode(v);
setStatus("idle");
}}
onComplete={(v) => setStatus(v === "123456" ? "valid" : "invalid")}
invalid={status === "invalid"}
aria-label="Verification code"
/>
<p className="h-4 text-xs text-muted-foreground" aria-live="polite">
{status === "valid" ? "Verified ✓" : status === "invalid" ? "Wrong code — try 123456" : "Type or paste 123456"}
</p>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/otp-input.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/input/otp-input.tsx.otp-input.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useAnimate, useReducedMotion } from "motion/react"; import { cn } from "@/lib/utils"; export interface OTPInputProps extends Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "maxLength"> { length?: number; value?: string; defaultValue?: string; onValueChange?: (value: string) => void; /** Called once every slot is filled. */ onComplete?: (value: string) => void; /** Insert a separator after every N slots. 0 to disable. */ groupSize?: number; /** Shake and turn red. */ invalid?: boolean; /** Characters allowed. Defaults to digits. */ pattern?: string; } /** * One-time-code field. A single real <input> sits invisibly over the slots, * so paste, SMS autofill (autocomplete="one-time-code"), backspace and screen * readers all work natively. The slots are just a visual layer. */ export function OTPInput({ length = 6, value, defaultValue = "", onValueChange, onComplete, groupSize = 3, invalid = false, pattern = "[0-9]", disabled, className, onFocus, onBlur, ...props }: OTPInputProps) { const id = React.useId(); const inputRef = React.useRef<HTMLInputElement>(null); const [scope, animate] = useAnimate<HTMLDivElement>(); const reduceMotion = useReducedMotion(); const [internal, setInternal] = React.useState(defaultValue); const [focused, setFocused] = React.useState(false); const current = (value ?? internal).slice(0, length); const allowed = React.useMemo(() => new RegExp(`^${pattern}$`), [pattern]); React.useEffect(() => { if (invalid && scope.current && !reduceMotion) { animate(scope.current, { x: [0, -6, 6, -4, 4, 0] }, { duration: 0.4 }); } }, [invalid, animate, scope, reduceMotion]); const update = (raw: string) => { const next = [...raw].filter((ch) => allowed.test(ch)).join("").slice(0, length); if (value === undefined) setInternal(next); onValueChange?.(next); if (next.length === length && current.length !== length) onComplete?.(next); }; const activeIndex = focused ? Math.min(current.length, length - 1) : -1; return ( <div ref={scope} className={cn("relative inline-flex items-center gap-1.5 sm:gap-2", disabled && "opacity-50", className)} > <input ref={inputRef} inputMode={pattern === "[0-9]" ? "numeric" : "text"} autoComplete="one-time-code" maxLength={length} value={current} disabled={disabled} aria-invalid={invalid || undefined} aria-label={props["aria-label"] ?? `${length}-character code`} className="absolute inset-0 z-10 cursor-text bg-transparent text-transparent caret-transparent outline-none selection:bg-transparent disabled:cursor-not-allowed" onChange={(e) => update(e.target.value)} onFocus={(e) => { setFocused(true); e.target.setSelectionRange(e.target.value.length, e.target.value.length); onFocus?.(e); }} onBlur={(e) => { setFocused(false); onBlur?.(e); }} // Keep the caret at the end so typing always fills the next slot. onSelect={(e) => { const el = e.currentTarget; el.setSelectionRange(el.value.length, el.value.length); }} {...props} /> {Array.from({ length }, (_, i) => { const char = current[i]; const isActive = i === activeIndex; return ( <React.Fragment key={i}> {groupSize > 0 && i > 0 && i % groupSize === 0 && ( <span aria-hidden className="h-0.5 w-2.5 rounded-full bg-border" /> )} <div aria-hidden className={cn( "relative flex size-10 items-center justify-center rounded-lg border sm:size-11 border-input bg-transparent font-mono text-lg font-medium shadow-xs transition-colors duration-200 dark:bg-input/30", invalid && "border-destructive text-destructive" )} > {isActive && ( <motion.span layoutId={`${id}-active`} className={cn( "absolute -inset-px rounded-lg border ring-[3px]", invalid ? "border-destructive ring-destructive/20" : "border-ring ring-ring/50" )} transition={{ type: "spring", duration: 0.25, bounce: 0 }} /> )} <AnimatePresence mode="popLayout" initial={false}> {char ? ( <motion.span key={char + i} initial={{ opacity: 0, y: 4 }} animate={{ opacity: 1, y: 0 }} exit={{ opacity: 0 }} transition={{ duration: 0.15, ease: "easeOut" }} > {char} </motion.span> ) : isActive ? ( <motion.span key="caret" className="h-5 w-px bg-foreground" animate={{ opacity: [1, 1, 0, 0] }} transition={{ duration: 1, repeat: Infinity, times: [0, 0.5, 0.5, 1] }} /> ) : null} </AnimatePresence> </div> </React.Fragment> ); })} </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| length | number | 6 | Number of slots. |
| value / onValueChange | string / (v: string) => void | — | Controlled value. |
| onComplete | (v: string) => void | — | Fires once all slots are filled. |
| invalid | boolean | false | Shake and show the error color. |
| groupSize | number | 3 | Separator every N slots; 0 to hide. |
| pattern | string | "[0-9]" | Regex for one allowed character. |
Floating Label
The label rests inside the field and moves up on focus or once filled — including browser autofill. It's a real <label>, so it stays accessible.
import { FloatingLabelInput } from "@/components/dusk/input/floating-label-input";
export default function FloatingLabelDemo() {
return (
<div className="grid w-full max-w-sm gap-3">
<FloatingLabelInput label="Full name" autoComplete="name" />
<FloatingLabelInput label="Company" defaultValue="DuskUI" />
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/floating-label-input.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/input/floating-label-input.tsx.floating-label-input.tsx "use client"; import * as React from "react"; import { motion } from "motion/react"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; export interface FloatingLabelInputProps extends React.ComponentProps<"input"> { label: string; } /** * The label sits inside the field like a placeholder and springs up when the * field is focused or filled. It is a real <label>, so it stays accessible. */ export function FloatingLabelInput({ label, id, className, value, defaultValue, onFocus, onBlur, onChange, ...props }: FloatingLabelInputProps) { const autoId = React.useId(); const inputId = id ?? autoId; const ref = React.useRef<HTMLInputElement>(null); const [focused, setFocused] = React.useState(false); const [hasText, setHasText] = React.useState(Boolean(defaultValue)); // Catch browser autofill, which may not fire onChange. React.useEffect(() => { const t = setTimeout(() => ref.current?.value && setHasText(true), 300); return () => clearTimeout(t); }, []); const filled = value !== undefined ? String(value).length > 0 : hasText; const floated = focused || filled; return ( <div className="relative w-full"> <Input ref={ref} id={inputId} value={value} defaultValue={defaultValue} className={cn("h-12 px-3 pb-1.5 pt-5", className)} onFocus={(e) => { setFocused(true); onFocus?.(e); }} onBlur={(e) => { setFocused(false); onBlur?.(e); }} onChange={(e) => { setHasText(e.target.value.length > 0); onChange?.(e); }} {...props} /> <motion.label htmlFor={inputId} className={cn( "pointer-events-none absolute left-3 top-0 origin-left text-sm leading-5 transition-colors duration-200", focused ? "text-primary" : "text-muted-foreground", props["aria-invalid"] && "text-destructive" )} initial={false} animate={floated ? { y: 5, scale: 0.78 } : { y: 14, scale: 1 }} transition={{ type: "spring", duration: 0.3, bounce: 0.1 }} > {label} </motion.label> </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | — | Label text. Required. |
Password Input
Show/hide toggle with a morphing eye icon and an optional four-step strength meter that fills with springs. The scoring helper passwordScore is exported so you can reuse it.
import { PasswordInput } from "@/components/dusk/input/password-input";
export default function PasswordInputDemo() {
return (
<div className="w-full max-w-sm">
<PasswordInput placeholder="Create a password" autoComplete="new-password" showStrength />
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/password-input.json1. Install the dependencies.
npm install motion lucide-react2. Copy the source into
components/dusk/input/password-input.tsx.password-input.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion } from "motion/react"; import { Eye, EyeOff } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; export interface PasswordInputProps extends Omit<React.ComponentProps<"input">, "type"> { /** Show a 4-step strength meter under the field. */ showStrength?: boolean; } const levels = [ { label: "Too short", color: "var(--color-destructive)" }, { label: "Weak", color: "var(--color-destructive)" }, { label: "Fair", color: "#f59e0b" }, { label: "Good", color: "#84cc16" }, { label: "Strong", color: "var(--color-primary)" }, ] as const; /** 0–4. Simple, dependency-free heuristic; swap in zxcvbn for real policies. */ export function passwordScore(value: string) { if (value.length < 8) return 0; let score = 1; if (/[a-z]/.test(value) && /[A-Z]/.test(value)) score++; if (/\d/.test(value) && /[^A-Za-z0-9]/.test(value)) score++; if (value.length >= 12) score++; return score; } const icon = { initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.8 }, transition: { type: "spring", duration: 0.25, bounce: 0 }, } as const; /** Password field with an animated show/hide toggle and optional strength meter. */ export function PasswordInput({ showStrength = false, className, value, defaultValue, onChange, ...props }: PasswordInputProps) { const meterId = React.useId(); const [visible, setVisible] = React.useState(false); const [internal, setInternal] = React.useState(String(defaultValue ?? "")); const current = value !== undefined ? String(value) : internal; const score = passwordScore(current); return ( <div className="w-full"> <div className="relative"> <Input type={visible ? "text" : "password"} autoComplete="current-password" value={value} defaultValue={defaultValue} aria-describedby={showStrength ? meterId : undefined} className={cn("pr-10", className)} onChange={(e) => { setInternal(e.target.value); onChange?.(e); }} {...props} /> <Button type="button" variant="ghost" size="icon-sm" aria-label={visible ? "Hide password" : "Show password"} aria-pressed={visible} className="absolute right-0.5 top-1/2 size-8 -translate-y-1/2 text-muted-foreground hover:text-foreground active:scale-90" onClick={() => setVisible((v) => !v)} > <span className="relative inline-flex"> <AnimatePresence mode="popLayout" initial={false}> <motion.span key={visible ? "hide" : "show"} className="inline-flex" {...icon}> {visible ? <EyeOff /> : <Eye />} </motion.span> </AnimatePresence> </span> </Button> </div> {showStrength && ( <div id={meterId} className="mt-2"> <div className="flex gap-1" aria-hidden> {[1, 2, 3, 4].map((step) => ( <div key={step} className="h-1 flex-1 overflow-hidden rounded-full bg-muted"> <motion.div className="h-full origin-left rounded-full" initial={false} animate={{ scaleX: current && score >= step ? 1 : 0, backgroundColor: levels[score].color, }} transition={{ type: "spring", duration: 0.4, bounce: 0, delay: (step - 1) * 0.04 }} /> </div> ))} </div> <p className="mt-1.5 h-4 text-xs text-muted-foreground" aria-live="polite"> {current && ( <> Strength: <span style={{ color: levels[score].color }}>{levels[score].label}</span> </> )} </p> </div> )} </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| showStrength | boolean | false | Render the strength meter. |
Search Input
The search icon turns into a spinner while results load, a clear button fades in once you type, Escape clears, and an optional ⌘ shortcut focuses the field from anywhere.
Next.js · Remix · Astro · Vite · Gatsby · Nuxt · SvelteKit
"use client";
import * as React from "react";
import { SearchInput } from "@/components/dusk/input/search-input";
const frameworks = ["Next.js", "Remix", "Astro", "Vite", "Gatsby", "Nuxt", "SvelteKit"];
export default function SearchInputDemo() {
const [query, setQuery] = React.useState("");
const [loading, setLoading] = React.useState(false);
const [results, setResults] = React.useState(frameworks);
React.useEffect(() => {
setLoading(true);
const t = setTimeout(() => {
setResults(frameworks.filter((f) => f.toLowerCase().includes(query.toLowerCase())));
setLoading(false);
}, 400);
return () => clearTimeout(t);
}, [query]);
return (
<div className="w-full max-w-sm">
<SearchInput
value={query}
onValueChange={setQuery}
loading={loading}
shortcut="j"
placeholder="Search frameworks…"
aria-label="Search frameworks"
/>
<p className="mt-3 text-xs text-muted-foreground">
{results.length ? results.join(" · ") : "No matches"}
</p>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/search-input.json1. Install the dependencies.
npm install motion lucide-react2. Copy the source into
components/dusk/input/search-input.tsx.search-input.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion } from "motion/react"; import { Loader2, Search, X } from "lucide-react"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; export interface SearchInputProps extends Omit<React.ComponentProps<"input">, "type" | "value" | "defaultValue" | "onChange"> { value?: string; defaultValue?: string; onValueChange?: (value: string) => void; /** Swap the search icon for a spinner while results load. */ loading?: boolean; /** Focus with ⌘/Ctrl + this key. Shows a hint while empty. */ shortcut?: string; } const pop = { initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.8 }, transition: { type: "spring", duration: 0.25, bounce: 0 }, } as const; /** Search field with loading spinner, animated clear button, Escape to clear and a ⌘K shortcut. */ export function SearchInput({ value, defaultValue = "", onValueChange, loading = false, shortcut, className, onKeyDown, placeholder = "Search…", ...props }: SearchInputProps) { const ref = React.useRef<HTMLInputElement>(null); const [internal, setInternal] = React.useState(defaultValue); const current = value ?? internal; const update = (next: string) => { if (value === undefined) setInternal(next); onValueChange?.(next); }; React.useEffect(() => { if (!shortcut) return; const onKey = (e: KeyboardEvent) => { if (e.key.toLowerCase() === shortcut.toLowerCase() && (e.metaKey || e.ctrlKey)) { e.preventDefault(); ref.current?.focus(); } }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [shortcut]); return ( <div className="group/search relative w-full"> <span className="pointer-events-none absolute left-3 top-1/2 inline-flex -translate-y-1/2 text-muted-foreground [&_svg]:size-4"> <AnimatePresence mode="popLayout" initial={false}> <motion.span key={loading ? "loading" : "idle"} className="inline-flex" {...pop}> {loading ? <Loader2 className="animate-spin" /> : <Search />} </motion.span> </AnimatePresence> </span> <Input ref={ref} type="search" value={current} placeholder={placeholder} aria-busy={loading || undefined} className={cn("pl-9 pr-16", className)} onChange={(e) => update(e.target.value)} onKeyDown={(e) => { if (e.key === "Escape" && current) { e.preventDefault(); update(""); } onKeyDown?.(e); }} {...props} /> <span className="absolute right-1.5 top-1/2 inline-flex -translate-y-1/2 items-center"> <AnimatePresence mode="popLayout" initial={false}> {current ? ( <motion.button key="clear" type="button" aria-label="Clear search" className="inline-flex size-6 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/50 [&_svg]:size-3.5" onClick={() => { update(""); ref.current?.focus(); }} {...pop} > <X /> </motion.button> ) : shortcut ? ( <motion.kbd key="kbd" className="pointer-events-none mr-0.5 hidden h-5 items-center gap-0.5 rounded border border-border bg-muted/60 px-1.5 font-mono text-[10px] text-muted-foreground sm:inline-flex transition-opacity group-focus-within/search:opacity-0" {...pop} > <span className="text-xs">⌘</span> {shortcut.toUpperCase()} </motion.kbd> ) : null} </AnimatePresence> </span> </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| value / onValueChange | string / (v: string) => void | — | Controlled value. |
| loading | boolean | false | Show the spinner. |
| shortcut | string | — | Key used with ⌘/Ctrl to focus, e.g. "k". |
Shimmer Input
A faint beam travels around the border while loading, for AI prompt fields while a response streams. Submit the demo to see it.
"use client";
import * as React from "react";
import { ArrowUp } from "lucide-react";
import { Button } from "@/components/ui/button";
import { ShimmerInput } from "@/components/dusk/input/shimmer-input";
export default function ShimmerInputDemo() {
const [loading, setLoading] = React.useState(false);
return (
<form
className="flex w-full max-w-md items-center gap-2"
onSubmit={(e) => {
e.preventDefault();
setLoading(true);
setTimeout(() => setLoading(false), 2500);
}}
>
<ShimmerInput loading={loading} placeholder="Ask anything…" aria-label="Prompt" />
<Button type="submit" size="icon" loading={loading} aria-label="Send">
<ArrowUp />
</Button>
</form>
);
}$ npx shadcn@latest add https://duskui.com/r/shimmer-input.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/input/shimmer-input.tsx.shimmer-input.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion } from "motion/react"; import { Input } from "@/components/ui/input"; import { cn } from "@/lib/utils"; export interface ShimmerInputProps extends React.ComponentProps<"input"> { /** Run the light around the border, e.g. while an AI response streams in. */ loading?: boolean; /** Classes for the outer border wrapper. */ wrapperClassName?: string; } /** * An input with a faint beam travelling around its border while `loading`. * The beam is a narrow rotating conic gradient clipped to a 1px frame. */ export function ShimmerInput({ loading = false, className, wrapperClassName, ...props }: ShimmerInputProps) { const reduceMotion = useReducedMotion(); return ( <div className={cn( "relative w-full overflow-hidden rounded-[calc(var(--radius)-1px)] bg-input p-px transition-shadow duration-200", "has-[input:focus-visible]:ring-[3px] has-[input:focus-visible]:ring-ring/50", wrapperClassName )} > <AnimatePresence> {loading && ( <motion.span aria-hidden className="pointer-events-none absolute left-1/2 top-1/2 aspect-square w-[max(200%,24rem)] -translate-x-1/2 -translate-y-1/2 bg-[conic-gradient(from_0deg,transparent_0%,transparent_82%,color-mix(in_oklab,var(--color-primary)_55%,transparent)_94%,transparent_100%)]" initial={{ opacity: 0 }} animate={{ opacity: 1, rotate: reduceMotion ? 0 : 360 }} exit={{ opacity: 0 }} transition={{ opacity: { duration: 0.3 }, rotate: { duration: 3, ease: "linear", repeat: Infinity }, }} /> )} </AnimatePresence> <Input aria-busy={loading || undefined} className={cn( "relative border-0 bg-card shadow-none hover:bg-card focus-visible:ring-0 dark:bg-card dark:hover:bg-card", className )} {...props} /> </div> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| loading | boolean | false | Run the border beam. |
| wrapperClassName | string | — | Classes for the border wrapper. |
API Reference
The base Input accepts every native <input> prop; styling hooks off native attributes like disabled, readOnly and aria-invalid.
| Prop | Type | Default | Description |
|---|---|---|---|
| type | string | "text" | Any native input type. |
| aria-invalid | boolean | — | Shows the destructive border and ring. |
| className | string | — | Merged with tailwind-merge, so overrides win. |
Accessibility
- Blocks never replace the native
<input>, so autofill, password managers and screen readers keep working. - Floating labels are real <label> elements linked with htmlFor.
- Password strength and OTP status are announced via aria-live; the visibility toggle uses aria-pressed.
- Spinners, rings and shakes respect prefers-reduced-motion.