Skip to content
search-example.tsx
A search button that opens into a search field, as one object.

Installation#
bunx --bun fabricator-ui@latest add search
Usage#
import { Search } from "@/components/ui/search"
import { Text } from "@/components/ui/text"<Search placeholder="Search components" />Examples#
import * as React from "react"
import { Search } from "@/components/ui/search"
import { Text } from "@/components/ui/text"
const FRAMEWORKS = ["Next.js", "Remix", "Astro", "Vite", "Gatsby", "Nuxt"]
function SearchExample() {
const [value, setValue] = React.useState("")
const [isOpen, setIsOpen] = React.useState(false)
const results = FRAMEWORKS.filter((name) =>
name.toLowerCase().includes(value.trim().toLowerCase())
)
return (
<ExampleWrapper fit>
<Example title="Collapsible">
<Search placeholder="Search components" />
</Example>
<Example title="Sizes">
<Search size="sm" />
<Search />
<Search size="lg" />
</Example>
<Example title="Outline">
<Search variant="outline" />
</Example>
<Example title="Always open">
<Search collapsible={false} width="100%" defaultValue="Button" />
</Example>
<Example title="No clear button">
<Search collapsible={false} clearable={false} width="100%" />
</Example>
<Example title="Disabled">
<Search collapsible={false} width="100%" editable={false} />
</Example>
<Example title="Controlled">
<Search
collapsible={false}
value={value}
onValueChange={setValue}
placeholder="Filter frameworks"
width="100%"
/>
<Text className="text-muted-foreground">
{value
? `${results.length} of ${FRAMEWORKS.length}: ${results.join(", ") || "none"}`
: `${FRAMEWORKS.length} frameworks`}
</Text>
</Example>
<Example title="Open from state">
<Search open={isOpen} onOpenChange={setIsOpen} width={240} />
<Text className="text-muted-foreground">
{isOpen ? "Open" : "Closed"}
</Text>
</Example>
</ExampleWrapper>
)
}
export { SearchExample }API reference#
| Prop | Values |
|---|---|
variant | default, outline |
size | default, lg, sm |
Differences from web#
Same. It works as it does on the web, with onPress for onClick.
Accessibility#
Parts set role="button", read by VoiceOver and TalkBack. Give a control with no text an accessibilityLabel.