Input Group
A React input group built on shadcn/ui: attach icons, prefixes, units, keyboard hints and buttons to an input or textarea, with one shared hover state, focus ring and invalid state — plus Motion blocks for a copy-to-clipboard field with a morphing check and a URL input whose protocol addon rolls between https and http.
- Drop-in shadcn API
- Input & textarea
- Inline and block addons
- Group focus ring
- Motion blocks
import { KeyRoundIcon } from "lucide-react";
import { CopyInput } from "@/components/dusk/input-group/copy-input";
export default function CopyInputDemo() {
return (
<div className="grid w-full max-w-md gap-4">
<CopyInput value="npx shadcn@latest add https://duskui.com/r/copy-input.json" aria-label="Install command" />
<CopyInput
value="dusk_test_4f9c2a7e1b3d"
addon={<KeyRoundIcon />}
copyLabel=""
aria-label="API key"
/>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/input-group.json1. Install the dependencies.
npm install class-variance-authority2. Copy the source into
components/ui/input-group.tsx.input-group.tsx "use client"; import * as React from "react"; import { cva, type VariantProps } from "class-variance-authority"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { cn } from "@/lib/utils"; /** * DuskUI Input Group — a drop-in upgrade of the shadcn/ui Input Group. * * Same parts, props and data-slot attributes as shadcn (InputGroup, * InputGroupAddon, InputGroupButton, InputGroupText, InputGroupInput, * InputGroupTextarea) plus: * - The whole group gets the Input's hover background, focus ring and red * invalid ring, so icons and buttons read as part of one field. * - Addon icons brighten while the control is focused. * - Addons on `inline-start` / `inline-end` sit beside the control; * `block-start` / `block-end` stack above or below it (toolbars, counters). * - Clicking an addon (outside its buttons) focuses the control. * - `data-disabled` on the group dims it. * CSS only, so nothing animates on the JS thread. */ function InputGroup({ className, ...props }: React.ComponentProps<"div">) { return ( <div data-slot="input-group" role="group" className={cn( "group/input-group relative flex w-full min-w-0 items-center rounded-md border border-input shadow-xs outline-none dark:bg-input/30", "transition-[color,background-color,border-color,box-shadow] duration-150 ease-out motion-reduce:transition-none", "h-9 has-[>textarea]:h-auto", "dark:hover:bg-input/40", // Pull the control's padding in next to inline addons. "has-[>[data-align=inline-start]]:[&>input]:pl-2", "has-[>[data-align=inline-end]]:[&>input]:pr-2", "has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3", "has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3", // Focus ring on the group, driven by the control inside. "has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50", // Invalid state from any control or addon button with aria-invalid. "has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40", "data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50", "has-[[data-slot=input-group-control]:disabled]:opacity-50", className )} {...props} /> ); } const inputGroupAddonVariants = cva( [ "flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none", "transition-colors duration-150 ease-out motion-reduce:transition-none", "group-has-[[data-slot=input-group-control]:focus-visible]/input-group:[&>svg]:text-foreground", "[&>svg:not([class*='size-'])]:size-4 [&>kbd]:rounded-[calc(var(--radius)-5px)]", "group-data-[disabled=true]/input-group:opacity-50", ], { variants: { align: { "inline-start": "order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]", "inline-end": "order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]", "block-start": "order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3", "block-end": "order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3", }, }, defaultVariants: { align: "inline-start" }, } ); /** Icons, text, keys or buttons attached to the control. `align` places it. */ function InputGroupAddon({ className, align = "inline-start", onClick, ...props }: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) { return ( <div role="group" data-slot="input-group-addon" data-align={align} className={cn(inputGroupAddonVariants({ align }), className)} onClick={(event) => { onClick?.(event); if (event.defaultPrevented || (event.target as HTMLElement).closest("button, a, input, textarea, select")) return; event.currentTarget.parentElement ?.querySelector<HTMLElement>("[data-slot=input-group-control]") ?.focus(); }} {...props} /> ); } const inputGroupButtonVariants = cva("flex items-center gap-2 text-sm shadow-none", { variants: { size: { xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 [&_svg:not([class*='size-'])]:size-3.5", sm: "h-8 gap-1.5 rounded-md px-2.5", "icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0", "icon-sm": "size-8 p-0", }, }, defaultVariants: { size: "xs" }, }); /** A compact DuskUI Button sized to sit inside the group. Defaults to `variant="ghost"`, `type="button"`. */ function InputGroupButton({ className, type = "button", variant = "ghost", size = "xs", ...props }: Omit<React.ComponentProps<typeof Button>, "size"> & VariantProps<typeof inputGroupButtonVariants>) { return ( <Button type={type} data-size={size} variant={variant} className={cn(inputGroupButtonVariants({ size }), className)} {...props} /> ); } /** Muted inline text inside an addon, e.g. a unit, a prefix or a counter. */ function InputGroupText({ className, ...props }: React.ComponentProps<"span">) { return ( <span className={cn( "flex items-center gap-2 text-sm text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4", className )} {...props} /> ); } const controlReset = "flex-1 rounded-none border-0 bg-transparent shadow-none hover:bg-transparent focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent dark:hover:bg-transparent read-only:bg-transparent disabled:opacity-100"; /** The DuskUI Input, unstyled so the group draws the border and ring. */ function InputGroupInput({ className, ...props }: React.ComponentProps<"input">) { return <Input data-slot="input-group-control" className={cn(controlReset, className)} {...props} />; } /** The DuskUI Textarea, unstyled so the group draws the border and ring. Still grows with its content. */ function InputGroupTextarea({ className, ...props }: React.ComponentProps<"textarea">) { return ( <Textarea data-slot="input-group-control" className={cn(controlReset, "resize-none py-3", className)} {...props} /> ); } export { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText, InputGroupInput, InputGroupTextarea };
Builds on the DuskUI Button, Input and Textarea, which the CLI installs for you.
Usage
import { SearchIcon } from "lucide-react"
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group"
export function Search() {
return (
<InputGroup>
<InputGroupInput placeholder="Search…" aria-label="Search" />
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
</InputGroup>
)
}Examples
Icons, text & keys
Addons go on inline-start (the default) or inline-end. Put the addon after the input in the markup — CSS order places it — so focus order stays natural. Icons brighten while the field is focused, and aria-invalid on the input turns the whole group red.
import { AtSignIcon, SearchIcon } from "lucide-react";
import { Kbd } from "@/components/ui/kbd";
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from "@/components/ui/input-group";
export default function InputGroupBasicDemo() {
return (
<div className="grid w-full max-w-sm gap-4">
<InputGroup>
<InputGroupInput placeholder="Search docs…" aria-label="Search docs" />
<InputGroupAddon>
<SearchIcon />
</InputGroupAddon>
<InputGroupAddon align="inline-end">
<Kbd>⌘K</Kbd>
</InputGroupAddon>
</InputGroup>
<InputGroup>
<InputGroupInput placeholder="handle" aria-label="Handle" />
<InputGroupAddon>
<AtSignIcon />
</InputGroupAddon>
<InputGroupAddon align="inline-end">
<InputGroupText>.dusk.dev</InputGroupText>
</InputGroupAddon>
</InputGroup>
<InputGroup>
<InputGroupAddon>
<InputGroupText>$</InputGroupText>
</InputGroupAddon>
<InputGroupInput inputMode="decimal" placeholder="0.00" aria-label="Amount" aria-invalid />
<InputGroupAddon align="inline-end">
<InputGroupText>USD</InputGroupText>
</InputGroupAddon>
</InputGroup>
</div>
);
}With a button
InputGroupButton is a compact DuskUI Button, so loading keeps its width while it shows a spinner.
"use client";
import * as React from "react";
import { MailIcon } from "lucide-react";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
export default function InputGroupButtonDemo() {
const [loading, setLoading] = React.useState(false);
return (
<form
className="w-full max-w-sm"
onSubmit={(event) => {
event.preventDefault();
setLoading(true);
setTimeout(() => setLoading(false), 1200);
}}
>
<InputGroup>
<InputGroupAddon>
<MailIcon />
</InputGroupAddon>
<InputGroupInput type="email" required placeholder="you@example.com" aria-label="Email" />
<InputGroupAddon align="inline-end">
<InputGroupButton type="submit" variant="soft" size="xs" loading={loading}>
Subscribe
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</form>
);
}Textarea with a toolbar
block-end stacks the addon under the control — handy for toolbars and counters. The textarea still grows with its content.
"use client";
import * as React from "react";
import { ArrowUpIcon, PaperclipIcon } from "lucide-react";
import {
InputGroup,
InputGroupAddon,
InputGroupButton,
InputGroupText,
InputGroupTextarea,
} from "@/components/ui/input-group";
const limit = 280;
export default function InputGroupTextareaDemo() {
const [text, setText] = React.useState("");
const left = limit - text.length;
return (
<InputGroup className="max-w-md">
<InputGroupTextarea
value={text}
onChange={(event) => setText(event.target.value.slice(0, limit))}
placeholder="Write a reply…"
aria-label="Reply"
aria-describedby="reply-count"
className="max-h-40"
/>
<InputGroupAddon align="block-end" className="border-t">
<InputGroupButton size="icon-xs" aria-label="Attach a file">
<PaperclipIcon />
</InputGroupButton>
<InputGroupText id="reply-count" className="ml-auto text-xs tabular-nums">
<span className={left < 20 ? "text-destructive" : undefined}>{left}</span>
<span className="sr-only"> characters left</span>
</InputGroupText>
<InputGroupButton variant="default" size="icon-xs" className="rounded-full" aria-label="Send" disabled={!text.trim()}>
<ArrowUpIcon />
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
);
}Blocks
Ready-made variations composed from the base component with Motion. Each installs on its own and pulls in its dependencies automatically.
Copy Input
A read-only field for API keys, invite links and install commands. On copy the icon swaps to a check and the label rolls to “Copied” without changing the button's width. Focus selects the whole value.
import { KeyRoundIcon } from "lucide-react";
import { CopyInput } from "@/components/dusk/input-group/copy-input";
export default function CopyInputDemo() {
return (
<div className="grid w-full max-w-md gap-4">
<CopyInput value="npx shadcn@latest add https://duskui.com/r/copy-input.json" aria-label="Install command" />
<CopyInput
value="dusk_test_4f9c2a7e1b3d"
addon={<KeyRoundIcon />}
copyLabel=""
aria-label="API key"
/>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/copy-input.json1. Install the dependencies.
npm install motion lucide-react2. Copy the source into
components/dusk/input-group/copy-input.tsx.copy-input.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion, type Transition } from "motion/react"; import { CheckIcon, CopyIcon } from "lucide-react"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group"; import { cn } from "@/lib/utils"; export interface CopyInputProps extends Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "readOnly" | "onCopy" | "children"> { /** The text to show and copy. */ value: string; /** Fires after a successful copy. */ onCopy?: (value: string) => void; /** How long the "Copied" state lasts, in ms. */ timeout?: number; /** Optional leading icon or text, e.g. `<KeyRound />` or `"npx"`. */ addon?: React.ReactNode; /** Button label before copying. Set to `""` for an icon-only button. */ copyLabel?: string; /** Button label after copying. */ copiedLabel?: string; /** Classes for the group. `className` styles the input. */ groupClassName?: string; } const iconSwap: Transition = { duration: 0.18, ease: "easeOut" }; async function writeClipboard(text: string) { try { await navigator.clipboard.writeText(text); return true; } catch { // Fallback for insecure contexts and older browsers. const area = document.createElement("textarea"); area.value = text; area.setAttribute("readonly", ""); area.style.position = "fixed"; area.style.opacity = "0"; document.body.appendChild(area); area.select(); const ok = document.execCommand("copy"); area.remove(); return ok; } } /** * A read-only field with a copy button — for API keys, invite links and * install commands. On copy the icon swaps to a check and the label rolls to * "Copied" without changing the button's width. Focusing the field selects the whole value. The result is * announced to screen readers. Under reduced motion it only cross-fades. */ export function CopyInput({ value, onCopy, timeout = 2000, addon, copyLabel = "Copy", copiedLabel = "Copied", groupClassName, className, onFocus, ...props }: CopyInputProps) { const reduceMotion = useReducedMotion() ?? false; const [copied, setCopied] = React.useState(false); const timer = React.useRef<number | undefined>(undefined); React.useEffect(() => () => window.clearTimeout(timer.current), []); const copy = async () => { const ok = await writeClipboard(value); if (!ok) return; setCopied(true); onCopy?.(value); window.clearTimeout(timer.current); timer.current = window.setTimeout(() => setCopied(false), timeout); }; const labelSwap = reduceMotion ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } } : { initial: { opacity: 0, y: 6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: -6 }, }; const iconMotion = reduceMotion ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } } : { initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.8 }, }; return ( <InputGroup className={cn("overflow-hidden", groupClassName)}> {addon && <InputGroupAddon>{addon}</InputGroupAddon>} <InputGroupInput readOnly value={value} spellCheck={false} onFocus={(event) => { event.currentTarget.select(); onFocus?.(event); }} className={cn("font-mono text-[0.8125rem] text-foreground/90", className)} {...props} /> <InputGroupAddon align="inline-end"> <InputGroupButton size={copyLabel ? "xs" : "icon-xs"} onClick={copy} aria-label={copyLabel ? undefined : copied ? copiedLabel : "Copy to clipboard"} className={cn("transition-colors", copied && "text-primary hover:text-primary")} > <span className="relative grid size-3.5 place-items-center"> <AnimatePresence initial={false} mode="popLayout"> <motion.span key={copied ? "check" : "copy"} {...iconMotion} transition={iconSwap} className="grid place-items-center [grid-area:1/1]" > {copied ? <CheckIcon className="size-3.5" /> : <CopyIcon className="size-3.5" />} </motion.span> </AnimatePresence> </span> {copyLabel ? ( // Both labels share one grid cell, so the button keeps the width of the longer one. <span className="relative grid overflow-hidden"> <span aria-hidden className="invisible [grid-area:1/1]"> {copyLabel} </span> <span aria-hidden className="invisible [grid-area:1/1]"> {copiedLabel} </span> <AnimatePresence initial={false} mode="popLayout"> <motion.span key={copied ? "copied" : "copy"} {...labelSwap} transition={iconSwap} className="text-left [grid-area:1/1]"> {copied ? copiedLabel : copyLabel} </motion.span> </AnimatePresence> </span> ) : null} </InputGroupButton> </InputGroupAddon> <span className="sr-only" aria-live="polite"> {copied ? "Copied to clipboard" : ""} </span> </InputGroup> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | — | The text to show and copy. Required. |
| onCopy | (value: string) => void | — | Fires after a successful copy. |
| timeout | number | 2000 | How long the copied state lasts (ms). |
| addon | ReactNode | — | Leading icon or text. |
| copyLabel / copiedLabel | string | "Copy" / "Copied" | Button labels. copyLabel="" makes it icon-only. |
URL Input
Paste a full address and the protocol lifts out of the text into the addon. Click the addon to switch between https and http — the padlock unlocks and the protocol rolls over — and a check or warning fades in as you type. The value always includes the protocol.
Value: https://duskui.com
"use client";
import * as React from "react";
import { UrlInput } from "@/components/dusk/input-group/url-input";
export default function UrlInputDemo() {
const [url, setUrl] = React.useState("https://duskui.com");
return (
<div className="grid w-full max-w-sm gap-2">
<label htmlFor="site-url" className="text-sm font-medium">
Website
</label>
<UrlInput id="site-url" value={url} onValueChange={setUrl} name="website" />
<p className="truncate text-xs text-muted-foreground">
Value: <span className="font-mono text-foreground/80">{url || "—"}</span>
</p>
</div>
);
}$ npx shadcn@latest add https://duskui.com/r/url-input.json1. Install the dependencies.
npm install motion lucide-react2. Copy the source into
components/dusk/input-group/url-input.tsx.url-input.tsx "use client"; import * as React from "react"; import { AnimatePresence, motion, useReducedMotion, type Transition } from "motion/react"; import { CircleAlertIcon, CircleCheckIcon, LockIcon, LockOpenIcon } from "lucide-react"; import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group"; import { cn } from "@/lib/utils"; type Protocol = "https://" | "http://"; export interface UrlInputProps extends Omit<React.ComponentProps<"input">, "value" | "defaultValue" | "type" | "children"> { /** The full URL including protocol (controlled). Empty string when the field is empty. */ value?: string; defaultValue?: string; onValueChange?: (url: string) => void; /** Show a check / warning icon once something is typed. */ showStatus?: boolean; /** Classes for the group. `className` styles the input. */ groupClassName?: string; } const spring: Transition = { type: "spring", duration: 0.25, bounce: 0 }; function split(url: string): { protocol: Protocol; rest: string } { const match = /^(https?):\/\//i.exec(url.trim()); if (!match) return { protocol: "https://", rest: url.trim() }; return { protocol: match[1].toLowerCase() === "http" ? "http://" : "https://", rest: url.trim().slice(match[0].length) }; } /** True for URLs with a dotted hostname (or localhost). */ export function isValidUrl(url: string) { try { const { hostname } = new URL(url); return hostname === "localhost" || /^[^.\s]+(\.[^.\s]+)+$/.test(hostname); } catch { return false; } } /** * A URL field with the protocol as an addon. Type or paste a full address * and "https://" is lifted out of the text into the addon; click the addon * to switch between https and http — the padlock unlocks and the protocol * rolls over. A check or warning pops in on the right as you type, and * `aria-invalid` is set once you leave an invalid URL. The value you get * back always includes the protocol. */ export function UrlInput({ value: valueProp, defaultValue = "", onValueChange, showStatus = true, groupClassName, className, onBlur, onPaste, name, disabled, "aria-invalid": ariaInvalid, ...props }: UrlInputProps) { const reduceMotion = useReducedMotion() ?? false; const [uncontrolled, setUncontrolled] = React.useState(defaultValue); const url = valueProp ?? uncontrolled; const [touched, setTouched] = React.useState(false); // The last protocol picked, so it survives clearing the field. const [protocolPref, setProtocolPref] = React.useState<Protocol>(() => split(url).protocol); const parsed = split(url); const rest = parsed.rest; const protocol = rest ? parsed.protocol : protocolPref; const valid = rest ? isValidUrl(protocol + rest) : true; const invalid = Boolean(ariaInvalid) || (touched && !valid); const secure = protocol === "https://"; const emit = (nextProtocol: Protocol, nextRest: string) => { const next = nextRest ? nextProtocol + nextRest : ""; if (valueProp === undefined) setUncontrolled(next); onValueChange?.(next); }; const handleChange = (text: string) => { const lifted = /^https?:\/\//i.test(text.trim()) ? split(text) : null; if (lifted) { setProtocolPref(lifted.protocol); emit(lifted.protocol, lifted.rest); } else { emit(protocol, text.replace(/^\s+/, "")); } }; const toggleProtocol = () => { const next: Protocol = secure ? "http://" : "https://"; setProtocolPref(next); emit(next, rest); }; const pop = reduceMotion ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } } : { initial: { opacity: 0, scale: 0.8 }, animate: { opacity: 1, scale: 1 }, exit: { opacity: 0, scale: 0.8 }, }; const roll = reduceMotion ? { initial: { opacity: 0 }, animate: { opacity: 1 }, exit: { opacity: 0 } } : { initial: { opacity: 0, y: secure ? 6 : -6 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: secure ? -6 : 6 }, }; return ( <InputGroup className={groupClassName} data-disabled={disabled || undefined}> <InputGroupAddon className="pr-0"> <button type="button" onClick={toggleProtocol} disabled={disabled} aria-label={`Protocol ${secure ? "https" : "http"}. Switch to ${secure ? "http" : "https"}`} className={cn( "-ml-1.5 inline-flex h-7 items-center gap-1.5 rounded-sm px-1.5 font-mono text-[0.8125rem] font-normal outline-none", "transition-[color,background-color] duration-200 hover:bg-accent/60 focus-visible:ring-2 focus-visible:ring-ring/60", secure ? "text-muted-foreground hover:text-foreground" : "text-amber-400/90 hover:text-amber-300" )} > <span className="relative grid size-3.5 place-items-center"> <AnimatePresence initial={false} mode="popLayout"> <motion.span key={secure ? "lock" : "open"} {...pop} transition={spring} className="grid [grid-area:1/1]"> {secure ? <LockIcon className="size-3.5" /> : <LockOpenIcon className="size-3.5" />} </motion.span> </AnimatePresence> </span> {/* Fixed to the width of "https://" so the input never shifts. */} <span className="relative grid overflow-hidden"> <span aria-hidden className="invisible [grid-area:1/1]"> https:// </span> <AnimatePresence initial={false} mode="popLayout"> <motion.span key={protocol} {...roll} transition={spring} className="text-left [grid-area:1/1]"> {protocol} </motion.span> </AnimatePresence> </span> </button> </InputGroupAddon> <InputGroupInput type="text" inputMode="url" autoComplete="url" autoCapitalize="none" spellCheck={false} placeholder="example.com" disabled={disabled} value={rest} aria-invalid={invalid || undefined} onChange={(event) => handleChange(event.target.value)} onPaste={(event) => { onPaste?.(event); if (event.defaultPrevented) return; const pasted = event.clipboardData.getData("text").trim(); // Pasting a full URL replaces the field, protocol included. if (/^https?:\/\//i.test(pasted) && event.currentTarget.selectionStart === 0) { event.preventDefault(); handleChange(pasted); } }} onBlur={(event) => { setTouched(true); onBlur?.(event); }} className={cn("pl-1", className)} {...props} /> {showStatus && ( <InputGroupAddon align="inline-end"> <span className="relative grid size-4 place-items-center"> <AnimatePresence initial={false} mode="popLayout"> {rest ? ( <motion.span key={valid ? "valid" : "invalid"} {...pop} transition={spring} className={cn("grid [grid-area:1/1]", valid ? "text-primary" : "text-amber-400/90")} > {valid ? <CircleCheckIcon className="size-4" /> : <CircleAlertIcon className="size-4" />} </motion.span> ) : null} </AnimatePresence> </span> <span className="sr-only" aria-live="polite"> {rest && touched ? (valid ? "Valid URL" : "This doesn't look like a valid URL") : ""} </span> </InputGroupAddon> )} {name && <input type="hidden" name={name} value={url} disabled={disabled} />} </InputGroup> ); }
| Prop | Type | Default | Description |
|---|---|---|---|
| value / onValueChange | string / (url: string) => void | — | Full URL with protocol; empty string when empty. |
| showStatus | boolean | true | Show the valid / invalid icon. |
| name | string | — | Submits the full URL with a hidden input. |
| groupClassName | string | — | Classes for the group; className goes to the input. |
API Reference
Each part accepts the props of the element it renders.
| Prop | Type | Default | Description |
|---|---|---|---|
| InputGroupAddon align | "inline-start" | "inline-end" | "block-start" | "block-end" | "inline-start" | Where the addon sits relative to the control. |
| InputGroupButton size | "xs" | "sm" | "icon-xs" | "icon-sm" | "xs" | Compact sizes that fit inside the group. variant defaults to ghost. |
| InputGroup data-disabled | boolean | — | Dims the whole group. |
| InputGroupInput / InputGroupTextarea | input / textarea props | — | The DuskUI controls with their own border and ring removed. |
Accessibility
- The group has
role="group"; still give the control a<label>oraria-label. - Icon-only buttons need an aria-label. Clicking an addon focuses the control.
- Copy Input and URL Input announce their result through a polite live region; the protocol toggle says which protocol it switches to.
- Icon and label swaps respect prefers-reduced-motion.