In this tutorial, we will see how to use search bar in next js 13 with shadcn ui. First you need to setup next js 13 with shadcn ui project.
how to use shadcn ui in next js 13
Before use search input in next js 13 with shadcn ui you need to install npx shadcn-ui@latest add input.
npx shadcn-ui@latest add input
or
npx shadcn-ui@latest add
Next 13 with Shadcn UI Search Bar Example
1. Create next js 13 with shadcn ui search bar using shadcn-ui Input, Button component.
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
export default function SearchBar() {
return (
<div className="flex items-center space-x-2">
<Input type="text" className="px-3 py-2 w-80" placeholder="Search..." />
<Button className="px-3 py-2">Search</Button>
</div>
)
}
2. next js 13 with shadcn ui search bar with search icon.
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
export default function SearchBar() {
return (
<div className="flex items-center space-x-2">
<Input type="text" className="px-3 py-2 w-80" placeholder="Search..." />
<Button className="px-3 py-2">
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
strokeWidth={1.5}
stroke="currentColor"
className="w-6 h-6"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"
/>
</svg>
</Button>
</div>
)
}
3. next js 13 with shadcn ui inside search bar with search icon.
import { Input } from "@/components/ui/input"
export default function SearchBar() {
return (
<div className="relative w-80">
<svg
xmlns="http://www.w3.org/2000/svg"
className="absolute top-0 bottom-0 w-6 h-6 my-auto text-gray-500 left-3"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"
/>
</svg>
<Input type="text" placeholder="Search" className="pl-12 pr-4" />
</div>
)
}
Related Posts
create a accordion in nextjs 13 with shadcn ui
create sidebar in next 13 with shadcn ui
create footer section in next 13 with shadcn ui
create file upload in nextjs 13 with shadcn ui
next 13 with shadcn ui input field example
next 13 with shadcn ui cards example
next 13 with shadcn ui login page example
next 13 with shadcn ui sign up form example
next 13 with shadcn ui radio group example
next 13 with shadcn ui buttons example
next 13 with shadcn ui pagination example
next 13 with shadcn ui table example
next 13 with shadcn ui checkbox example
next 13 with shadcn ui dropdown menu example
how to use skeleton loading next 13 with shadcn ui
how to use data table next 13 with shadcn ui
how to use modal dialog next 13 with shadcn ui
how to use tabs next 13 with shadcn ui
how to use toggle switch next 13 with shadcn ui