Search input groups
Five search bar compositions with real behavior: a plain field, a clear button that empties the input and returns focus, a locally handled submit, a scope filter and a voice affordance. The microphone is decorative only and calls no audio API.
Installation
The styled layer is free and installs like any other ai2 component.
Run the following command
npx shadcn@latest add @ai2/input-group-searchDependencies, the @ai2/tokens theme and the component file are installed together.
Install dependencies
npm install lucide-reactCopy the source
components/ui/input-group-search.tsx"use client"
import * as React from "react"
import { Mic, Search, SlidersHorizontal, X } from "lucide-react"
import { cn } from "@/lib/utils"
/* Search input group family: 5 search-bar compositions, with REAL behavior.
search (a plain field), clear (the clear button genuinely empties the field and
returns focus), submit (form submission is prevented and the query stays in local
state), filter (a scope selector + the field), voice (the microphone is ONLY a
visual affordance - no microphone/audio API is ever called and there is no fake
recording; clicking it merely toggles a visual "listening" state). Color comes
ONLY from tokens, via alpha color-mix. No motion. Every field has an accessible
label. */
export type StyledSize = "sm" | "md" | "lg" | "xl"
const height: Record<StyledSize, string> = {
sm: "h-8 text-sm",
md: "h-9 text-sm",
lg: "h-10 text-base",
xl: "h-12 text-base",
}
const rootBase =
"group inline-flex w-64 max-w-full items-center overflow-hidden rounded-lg border border-field-border bg-transparent transition-colors duration-(--motion-base) focus-within:border-primary focus-within:ring-[3px] focus-within:ring-ring/50 [&_svg]:size-4 [&_svg]:shrink-0 [&_i]:text-base [&_i]:leading-none"
const fieldBase =
"h-full w-full min-w-0 bg-transparent px-2 text-foreground outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50"
const iconBtn =
"mr-1.5 inline-flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-[color-mix(in_oklab,var(--color-foreground)_8%,transparent)] hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50"
type Props = Omit<React.ComponentProps<"input">, "size"> & { size?: StyledSize }
/* Search: onde arama ikonu tasiyan yalin arama alani. */
export function SearchGroup({ className, size = "md", ...props }: Props) {
const id = React.useId()
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<label htmlFor={id} className="sr-only">
Search
</label>
<Search className="ml-3 shrink-0 text-muted-foreground transition-colors group-focus-within:text-primary" />
<input id={id} type="search" placeholder="Search" {...props} className={fieldBase} />
</div>
)
}
/* Clear: the button on the right REALLY clears the field and returns focus to it. The button only appears when there is a value. */
export function ClearGroup({ className, size = "md", ...props }: Props) {
const id = React.useId()
const [value, setValue] = React.useState("")
const inputRef = React.useRef<HTMLInputElement>(null)
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<label htmlFor={id} className="sr-only">
Search with clear
</label>
<Search className="ml-3 shrink-0 text-muted-foreground transition-colors group-focus-within:text-primary" />
<input
id={id}
ref={inputRef}
type="search"
placeholder="Search"
{...props}
value={value}
onChange={(e) => setValue(e.target.value)}
className={cn(fieldBase, "[&::-webkit-search-cancel-button]:appearance-none")}
/>
{value ? (
<button
type="button"
aria-label="Clear search"
className={iconBtn}
onClick={() => {
setValue("")
inputRef.current?.focus()
}}
>
<X />
</button>
) : null}
</div>
)
}
/* Submit: a real form; submission is prevented (no network request), the query is held in local state and announced with aria-live. */
export function SubmitGroup({ className, size = "md", ...props }: Props) {
const id = React.useId()
const [value, setValue] = React.useState("")
const [submitted, setSubmitted] = React.useState("")
return (
<form
data-slot="styled-input-group"
className={cn(rootBase, height[size], className)}
onSubmit={(e) => {
e.preventDefault()
setSubmitted(value)
}}
>
<label htmlFor={id} className="sr-only">
Search and submit
</label>
<Search className="ml-3 shrink-0 text-muted-foreground transition-colors group-focus-within:text-primary" />
<input
id={id}
type="search"
placeholder="Search"
{...props}
value={value}
onChange={(e) => setValue(e.target.value)}
className={fieldBase}
/>
<span aria-live="polite" className="sr-only">
{submitted ? `Searched for ${submitted}` : ""}
</span>
<button
type="submit"
className="flex h-full shrink-0 select-none items-center border-l border-field-border bg-secondary px-3 text-sm font-medium text-secondary-foreground outline-none transition-colors hover:bg-surface-3 focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
Search
</button>
</form>
)
}
/* Filter: solda kapsam secimi, sagda filtre ikonu tasiyan arama alani. */
export function FilterGroup({ className, size = "md", ...props }: Props) {
const id = React.useId()
return (
<div data-slot="styled-input-group" className={cn(rootBase, height[size], className)}>
<select
aria-label="Search scope"
className="h-full shrink-0 select-none border-r border-field-border bg-surface-2 pl-3 pr-2 text-muted-foreground outline-none transition-colors focus-visible:ring-[3px] focus-visible:ring-ring/50"
>
<option value="all">All</option>
<option value="docs">Docs</option>
<option value="code">Code</option>
</select>
<label htmlFor={id} className="sr-only">
Filtered search
</label>
<input id={id} type="search" placeholder="Search" {...props} className={fieldBase} />
<SlidersHorizontal className="mr-3 shrink-0 text-muted-foreground" />
</div>
)
}
/* Voice: the microphone button is ONLY a visual affordance. No microphone,
MediaRecorder or SpeechRecognition API is ever called; the button merely toggles a
visual "listening" state and announces that state accessibly. */
export function VoiceGroup({ className, size = "md", ...props }: Props) {
const id = React.useId()
const [listening, setListening] = React.useState(false)
return (
<div
data-slot="styled-input-group"
data-listening={listening ? "true" : undefined}
className={cn(
rootBase,
height[size],
listening && "border-primary bg-[color-mix(in_oklab,var(--color-primary)_8%,transparent)]",
className
)}
>
<label htmlFor={id} className="sr-only">
Voice search
</label>
<Search className="ml-3 shrink-0 text-muted-foreground transition-colors group-focus-within:text-primary" />
<input id={id} type="search" placeholder="Search" {...props} className={fieldBase} />
<button
type="button"
aria-pressed={listening}
aria-label={listening ? "Stop voice input" : "Start voice input"}
className={cn(iconBtn, listening && "bg-primary text-primary-foreground hover:bg-primary")}
onClick={() => setListening((v) => !v)}
>
<Mic />
</button>
</div>
)
}Manual installs skip the @ai2/tokens theme, so add the token CSS from the theming guide or the tone colors will be missing.
Variations
5 takes on the same idea. Each is its own export, and every one accepts a size prop (sm, md, lg, xl) aligned to the base Button scale.
Search
A plain search field with a leading icon.
import { SearchGroup } from "@/components/ui/input-group-search"
<SearchGroup placeholder="Search" />Clear
A clear button that really empties the field and returns focus.
import { ClearGroup } from "@/components/ui/input-group-search"
<ClearGroup placeholder="Search" />Submit
A real form whose submit is handled locally, with no network call.
import { SubmitGroup } from "@/components/ui/input-group-search"
<SubmitGroup placeholder="Search" />Filter
A scope select attached before the search field.
import { FilterGroup } from "@/components/ui/input-group-search"
<FilterGroup placeholder="Search" />Voice
A microphone button that is a visual affordance only, with no audio API.
import { VoiceGroup } from "@/components/ui/input-group-search"
<VoiceGroup placeholder="Search" />ai2 Search input groups: 5 styled variations on the token system
The ai2 Search input groups are a set of 5 decorative button variations from the styled layer of the @ai2 design system, built around search bars with working clear, submit and filter behavior. They are free and MIT licensed, and every color comes from a semantic token, so they theme with the rest of ai2 in light and dark.
Motion runs on framer-motion: focus-within highlights run on token CSS transitions. The styled layer is opt-in, so the dependency only lands if you use it; the base components stay lean. Under reduced motion, the transitions are disabled and every action still works.
What is in the ai2 Search input groups?
5 exports in one file: Search, Clear, Submit, Filter and Voice. Each renders a native button and takes a size prop (sm, md, lg, xl) aligned to the base Button. They are separate from the base Button on purpose: the base keeps its clean variant, tone and size axes, while the styled layer carries the effects.
You own the file. Copy the one category file and you have all 5 variations, with no runtime dependency on ai2 itself.
Why use it
- On-system by construction: Every color resolves to an ai2 semantic token, so the buttons follow your theme in light and dark with no extra work.
- Effect without the sprawl: The decorations live in a dedicated styled file, so the base Button keeps its clean, predictable API.
- Accessible and honest: Each renders a real button element, keeps a visible focus ring, and respects prefers-reduced-motion.
Features
- Token-driven color: No hardcoded hex or oklch; the look recolors with your theme tokens.
- framer-motion: focus-within highlights run on token CSS transitions.
- Reduced-motion aware: Under prefers-reduced-motion, the transitions are disabled and every action still works.
- Size aligned to the base: Every variation takes sm, md, lg and xl matching the base Button height scale, so styled and base buttons line up in a row.
Production tips
- Use it for emphasis, not everywhere: Styled buttons draw the eye. Reserve them for the one action you want people to take on a screen, and use the base Button for the rest.
- Keep labels as verbs: The decoration adds weight, so a clear action label keeps the button scannable.
- Pick one variation per surface: The variations share a family; using two different ones in the same view competes for attention.
Works with the rest of ai2
The Search input groups sit alongside the base Button and the rest of the @ai2 registry. They share the same token file, so a styled action next to a base button or a badge stays visually consistent in both modes.