Select
BaseNative dropdown select with custom styling.
Preview
Usage
example.jsx
import { Select, SelectOption } from "@/components/ui/select";
export default function Example() {
return <Select />;
}Source Code
Copy this file into components/ui/select.jsx in your project.
select.jsx
"use client";
import { forwardRef } from "react";
import { cn } from "@/lib/utils";
const Select = forwardRef(({ className, children, ...props }, ref) => {
return (
<select
ref={ref}
className={cn(
"flex h-9 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm",
"ring-offset-background placeholder:text-muted-foreground",
"focus:outline-none focus:ring-1 focus:ring-ring",
"disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
>
{children}
</select>
);
});
Select.displayName = "Select";
const SelectOption = forwardRef(({ className, ...props }, ref) => {
return (
<option
ref={ref}
className={cn("bg-background text-foreground", className)}
{...props}
/>
);
});
SelectOption.displayName = "SelectOption";
export { Select, SelectOption };
Quick Install
Make sure you have the cn() utility set up. It requires clsx and tailwind-merge.
npm install clsx tailwind-merge