Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Recent Selections Section Combobox for Svelte

A file combobox with package.json and index.tsx under Recent, above the rest of the files.

UI library: Ark UI

package.json and index.tsx sit under Recent with a clock icon. README.md, tsconfig.json, and App.tsx follow under All Files. A rule separates the two.

Use it for file pickers and switchers, where people return to the same few files. A starred list, rather than a recent one, is the same pattern on a Combobox. In Svelte, Ark UI does not track what was opened.

Preview

Preview width

Installation

MCP · Pro
Make your AI a shadcn expert
Your agent installs components, builds pages and restyles your app from one prompt, in Claude Code, Cursor or VS Code.
Part of Pro

Anatomy

Combobox anatomy: control, input, trigger, content, item, item indicator

Usage

<Combobox collection={collection} onInputValueChange={handleInputValueChange} onValueChange={handleValueChange} positioning={{ getAnchorElement: () => triggerRef }} selectionBehavior="clear" value={value}><ComboboxTrigger class={cn(
          buttonVariants({ variant: "outline" }),
          "w-[250px] justify-between"
        )} bind:ref={triggerRef}>{#if selected}{selected.label}{:else}{"Select file..."}{/if}</ComboboxTrigger><ComboboxContent><ComboboxInput class="w-full" placeholder="Search files..." showTrigger={false} /><ComboboxEmpty>No file found.</ComboboxEmpty><ComboboxList>{#each groups as [group, items], index (group)}<ComboboxGroup heading={group}>{#each items as item (item.value)}<ComboboxItem class="gap-2" item={item}>{#if item.group === "Recent"}<ClockIcon aria-hidden="true" class="size-3 opacity-50" />{:else}{/if}{item.label}</ComboboxItem>{/each}</ComboboxGroup>{#if index < groups.length - 1}<ComboboxSeparator />{:else}{/if}{/each}</ComboboxList></ComboboxContent></Combobox>

FAQ

How are the two sections built?

Two ComboboxGroups, Recent and All Files, with a ComboboxSeparator between them. groupBy in useListCollection splits the files, and heading names each group.

How is the clock drawn?

A ClockIcon at size-3 opacity-50, only in the Recent rows and hidden from screen readers.

Why aren't recent files listed twice?

All Files leaves out the recent ones, so each file has one row and one value.

Does Recent update when I pick a file?

Not in this demo: the list is fixed. Store the last few picks, newest first, and build the Recent group from them to make it live.

What does the button show?

The picked file name, or Select file... before a pick.

API Reference

Combobox

Sets collection={collection}, onInputValueChange={handleInputValueChange}, onValueChange={handleValueChange}, positioning, getAnchorElement and cn. The rest is on the Combobox page.