Animated Select
1 variant
A composable select whose menu drops out of a pill trigger, with a gliding highlight, a checkmark on the chosen item, icons, descriptions, groups, separators, and optional search.
Animated select
animated-select.tsxCompose it from Trigger, Value, Content, Item, Group, and Separator. The menu opens in a portal so scrolling containers and dialogs never clip it, and it flips above the trigger when there's more room. Arrow keys, Page Up and Down, Home, End, and typing a name move the highlight. It works controlled or uncontrolled, submits with forms, and marks itself invalid when a required value is missing.
Status
Plan
Time zone
TSXcomponents/previews/premium/animated-select-preview.tsx
"use client";
import {
CheckCircle2,
CircleDashed,
CircleDot,
PauseCircle,
} from "lucide-react";
import { type ReactNode, useId, useState } from "react";
import {
AnimatedModal,
AnimatedModalBody,
AnimatedModalFooter,
AnimatedModalHeader,
AnimatedModalTitle,
} from "@/components/motion/animated-modal";
import { Button } from "@/components/motion/button";
import {
AnimatedSelect,
AnimatedSelectContent,
AnimatedSelectGroup,
AnimatedSelectItem,
AnimatedSelectSeparator,
AnimatedSelectTrigger,
AnimatedSelectValue,
} from "@/components/premium/animated-select";
const STATUS = [
{ value: "todo", label: "To do", icon: CircleDashed },
{ value: "doing", label: "In progress", icon: CircleDot },
{ value: "paused", label: "Paused", icon: PauseCircle },
{ value: "done", label: "Done", icon: CheckCircle2 },
];
const ZONES: [string, [string, string][]][] = [
[
"Americas",
[
["Los Angeles", "UTC−8"],
["Chicago", "UTC−6"],
["New York", "UTC−5"],
["São Paulo", "UTC−3"],
],
],
[
"Europe",
[
["London", "UTC+0"],
["Berlin", "UTC+1"],
["Athens", "UTC+2"],
],
],
[
"Asia & Pacific",
[
["Dubai", "UTC+4"],
["Bengaluru", "UTC+5:30"],
["Singapore", "UTC+8"],
["Tokyo", "UTC+9"],
["Sydney", "UTC+10"],
],
],
];
const slug = (text: string) => text.toLowerCase().replace(/\s+/g, "-");
function Field({
label,
children,
}: {
label: string;
children: (labelId: string) => ReactNode;
}) {
const id = useId();
return (
<div className="flex flex-col gap-1.5">
<span id={id} className="px-1 text-muted-foreground text-xs">
{label}
</span>
{children(id)}
</div>
);
}
function StatusSelect({ labelId }: { labelId: string }) {
const [status, setStatus] = useState("doing");
return (
<AnimatedSelect value={status} onValueChange={setStatus}>
<AnimatedSelectTrigger aria-labelledby={labelId} className="w-44" />
<AnimatedSelectContent>
{STATUS.map((item) => (
<AnimatedSelectItem
key={item.value}
value={item.value}
icon={item.icon}
>
{item.label}
</AnimatedSelectItem>
))}
</AnimatedSelectContent>
</AnimatedSelect>
);
}
function PlanSelect({ labelId }: { labelId: string }) {
return (
<AnimatedSelect defaultValue="team" name="plan">
<AnimatedSelectTrigger aria-labelledby={labelId} className="w-44" />
<AnimatedSelectContent>
<AnimatedSelectItem
value="starter"
description="One project, community help"
>
Starter
</AnimatedSelectItem>
<AnimatedSelectItem
value="team"
description="Unlimited projects, 10 seats"
>
Team
</AnimatedSelectItem>
<AnimatedSelectItem
value="scale"
description="SSO, audit log, priority help"
>
Scale
</AnimatedSelectItem>
<AnimatedSelectSeparator />
<AnimatedSelectItem
value="legacy"
description="No longer offered"
disabled
>
Legacy
</AnimatedSelectItem>
</AnimatedSelectContent>
</AnimatedSelect>
);
}
function ZoneSelect({
labelId,
required,
}: {
labelId: string;
required?: boolean;
}) {
return (
<AnimatedSelect name="zone" required={required}>
<AnimatedSelectTrigger aria-labelledby={labelId} className="w-56">
<AnimatedSelectValue placeholder="Pick a time zone" />
</AnimatedSelectTrigger>
<AnimatedSelectContent
searchable
searchPlaceholder="Search cities"
emptyText="No city matches"
>
{ZONES.map(([region, cities]) => (
<AnimatedSelectGroup key={region} label={region}>
{cities.map(([city, offset]) => (
<AnimatedSelectItem
key={city}
value={slug(city)}
description={offset}
>
{city}
</AnimatedSelectItem>
))}
</AnimatedSelectGroup>
))}
</AnimatedSelectContent>
</AnimatedSelect>
);
}
export function AnimatedSelectPreview() {
const [dialogOpen, setDialogOpen] = useState(false);
return (
<div className="flex flex-col items-center gap-6 p-6">
<div className="flex flex-wrap items-end justify-center gap-4">
<Field label="Status">{(id) => <StatusSelect labelId={id} />}</Field>
<Field label="Plan">{(id) => <PlanSelect labelId={id} />}</Field>
<Field label="Time zone">{(id) => <ZoneSelect labelId={id} />}</Field>
</div>
<Button
variant="ghost"
size="sm"
onClick={() => setDialogOpen(true)}
className="h-8 px-3 text-xs"
>
Try it in a dialog
</Button>
<AnimatedModal open={dialogOpen} onOpenChange={setDialogOpen} size="sm">
<form
onSubmit={(event) => {
event.preventDefault();
setDialogOpen(false);
}}
>
<AnimatedModalHeader>
<AnimatedModalTitle className="font-medium text-xl">
Meeting settings
</AnimatedModalTitle>
</AnimatedModalHeader>
<AnimatedModalBody className="flex flex-col gap-4">
<Field label="Time zone">
{(id) => <ZoneSelect labelId={id} required />}
</Field>
<Field label="Status">
{(id) => <StatusSelect labelId={id} />}
</Field>
</AnimatedModalBody>
<AnimatedModalFooter>
<Button
variant="outline"
type="button"
onClick={() => setDialogOpen(false)}
>
Cancel
</Button>
<Button type="submit">Save</Button>
</AnimatedModalFooter>
</form>
</AnimatedModal>
</div>
);
}
Source code is locked
Get access to install premium components and view the full source.
Open dashboardInstall
$ bunx --bun shadcn add @beui-pro/animated-select