Aurora Listbox
aurora-dinglebear-ai/aurora-listboxUnverifiedComponent
Shared Aurora listbox, group, and option row primitives for command palettes, search results, and combobox menus.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/dinglebear-ai/aurora/main/aurora-listbox.jsonSource
1"use client"23import * as React from "react"4import { Button } from "./button"5import { cn } from "@/lib/utils"67type ListboxOrientation = "vertical" | "horizontal"89export interface ListboxProps extends React.HTMLAttributes<HTMLDivElement> {10 orientation?: ListboxOrientation11}1213function Listbox({14 className,15 style,16 ref,17 orientation = "vertical",18 onKeyDown,19 ...props20}: ListboxProps & { ref?: React.Ref<HTMLDivElement> }) {21 const handleKeyDown = React.useCallback(22 (event: React.KeyboardEvent<HTMLDivElement>) => {23 onKeyDown?.(event)24 if (event.defaultPrevented) return2526 const root = event.currentTarget27 const options = Array.from(28 root.querySelectorAll<HTMLButtonElement>('[role="option"]:not(:disabled)'),29 )3031 if (options.length === 0) return3233 const activeElement =34 event.target instanceof HTMLElement35 ? event.target.closest<HTMLButtonElement>('[role="option"]')36 : null37 const currentIndex = activeElement38 ? options.indexOf(activeElement)39 : options.findIndex((option) => option.getAttribute("aria-selected") === "true")4041 let nextIndex = currentIndex >= 0 ? currentIndex : 042 const nextKey = orientation === "horizontal" ? "ArrowRight" : "ArrowDown"43 const previousKey = orientation === "horizontal" ? "ArrowLeft" : "ArrowUp"4445 if (event.key === nextKey) {46 nextIndex = currentIndex >= 0 ? (currentIndex + 1) % options.length : 047 } else if (event.key === previousKey) {48 nextIndex =49 currentIndex >= 050 ? (currentIndex - 1 + options.length) % options.length51 : options.length - 152 } else if (event.key === "Home") {53 nextIndex = 054 } else if (event.key === "End") {55 nextIndex = options.length - 156 } else {57 return58 }5960 event.preventDefault()61 const nextOption = options[nextIndex]62 nextOption.focus()63 },64 [onKeyDown, orientation],65 )6667 return (68 <div69 ref={ref}70 role="listbox"71 aria-orientation={orientation}72 className={cn(73 "overflow-hidden rounded-[var(--aurora-radius-2)] border p-2",74 className,75 )}76 style={{77 background: "var(--aurora-panel-strong)",78 borderColor: "var(--aurora-border-strong)",79 boxShadow: "var(--aurora-shadow-strong), var(--aurora-highlight-strong)",80 ...style,81 }}82 onKeyDown={handleKeyDown}83 {...props}84 />85 )86}8788// … truncated
What it pulls in
Other registry items
Files it writes
More from aurora
All 176 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Aurora Accordionaurora-accordion | aurora | Components | Unverified | 2 deps | |
| Aurora Alert Dialogaurora-alert-dialog | aurora | Components | Unverified | 2 deps | |
| Aurora Aspect Ratioaurora-aspect-ratio | aurora | Components | Unverified | no deps | |
| Aurora Avataraurora-avatar | aurora | Components | Unverified | 1 dep | |
| Aurora Badgeaurora-badge | aurora | Components | Unverified | 2 deps | |
| Aurora Banneraurora-banner | aurora | Components | Unverified | 1 dep | |
| Aurora Breadcrumbaurora-breadcrumb | aurora | Components | Unverified | 2 deps | |
| Aurora Buttonaurora-button | aurora | Components | Unverified | 2 deps |
