Select
basecn/selectFreeComponent
Displays a list of options for the user to pick from—triggered by a button.
Live preview
live · rendered by the registry
Rendered by basecn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://basecn.dev/r/select.jsonSource
1"use client";23import * as React from "react";4import { Select as SelectPrimitive } from "@base-ui/react/select";5import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";67import { cn } from "@/lib/utils";89const Select = SelectPrimitive.Root;1011function SelectGroup({ ...props }: SelectPrimitive.Group.Props) {12 return <SelectPrimitive.Group data-slot="select-group" {...props} />;13}1415function SelectValue({16 placeholder,17 ...props18}: SelectPrimitive.Value.Props & {19 placeholder?: string;20}) {21 if (!placeholder) {22 return <SelectPrimitive.Value data-slot="select-value" {...props} />;23 }2425 return (26 <SelectPrimitive.Value27 render={(_, { value }) => {28 if (value) {29 return <SelectPrimitive.Value data-slot="select-value" {...props} />;30 }3132 // Placeholder33 return (34 <span data-slot="select-value" className="text-muted-foreground">35 {placeholder}36 </span>37 );38 }}39 {...props}40 />41 );42}4344function SelectTrigger({45 className,46 size = "default",47 children,48 ...props49}: SelectPrimitive.Trigger.Props & {50 size?: "sm" | "default";51}) {52 return (53 <SelectPrimitive.Trigger54 data-slot="select-trigger"55 data-size={size}56 className={cn(57 "border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",58 className59 )}60 {...props}61 >62 {children}63 <SelectPrimitive.Icon64 render={<ChevronDownIcon className="size-4 opacity-50" />}65 />66 </SelectPrimitive.Trigger>67 );68}6970function SelectPositioner({71 className,72 ...props73}: SelectPrimitive.Positioner.Props) {74 return (75 <SelectPrimitive.Portal>76 <SelectPrimitive.Positioner77// … truncated
What it pulls in
npm packages
Files it writes
More from basecn
All 56 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | basecn | Components | Free | 2 deps | |
| Alertalert | basecn | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | basecn | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | basecn | Components | Free | no deps | |
| Autocompleteautocomplete | basecn | Components | Free | 2 deps | |
| Avataravatar | basecn | Components | Free | 1 dep | |
| Badgebadge | basecn | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | basecn | Components | Free | 2 deps |
