Files
Aidan Bleser 7f5289a709 parity: select (#2883)
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Aidan Bleser <aidanbleser35@gmail.com>
2026-09-11 11:50:41 -07:00

2.8 KiB

title, description, component, links
title description component links
Select Displays a list of options for the user to pick from—triggered by a button. true
source doc api
https://github.com/huntabyte/shadcn-svelte/tree/next/sites/docs/src/lib/registry/ui/select https://bits-ui.com/docs/components/select https://bits-ui.com/docs/components/select#api-reference
<script> import ComponentPreview from "$lib/components/component-preview.svelte"; import ComponentSource from "$lib/components/component-source.svelte"; import PMAddComp from "$lib/components/pm-add-comp.svelte"; import PMInstall from "$lib/components/pm-install.svelte"; import Steps from "$lib/components/steps.svelte"; import InstallTabs from "$lib/components/install-tabs.svelte"; let { viewerData } = $props(); import Step from "$lib/components/step.svelte"; </script>

Installation

{#snippet cli()} {/snippet} {#snippet manual()}

Install bits-ui:

Copy and paste the following code into your project.

{#if viewerData} {/if} {/snippet}

Usage

<script lang="ts">
  import * as Select from "$lib/components/ui/select/index.js";
</script>
<Select.Root type="single">
  <Select.Trigger class="w-[180px]">
    <Select.Value placeholder="Select a theme" />
  </Select.Trigger>
  <Select.Content>
    <Select.Item value="light">Light</Select.Item>
    <Select.Item value="dark">Dark</Select.Item>
    <Select.Item value="system">System</Select.Item>
  </Select.Content>
</Select.Root>

Select.Value renders the label of the selected item, falling back to placeholder when nothing is selected.

It reads the label from the matching Select.Item, which only exists in the DOM while the menu is open. Pass items to Select.Root so the label survives the menu closing:

<script lang="ts">
  const themes = [
    { value: "light", label: "Light" },
    { value: "dark", label: "Dark" },
    { value: "system", label: "System" },
  ];
</script>

<Select.Root type="single" items={themes}>
  <Select.Trigger class="w-[180px]">
    <Select.Value placeholder="Select a theme" />
  </Select.Trigger>
  <Select.Content>
    {#each themes as theme (theme.value)}
      <Select.Item value={theme.value}>{theme.label}</Select.Item>
    {/each}
  </Select.Content>
</Select.Root>

Without items the trigger falls back to the raw value, so you only need it when an item's label differs from its value.

Examples

Scrollable