Files
svelte/SelectTrigger.svelte
zeekayandHanzo Dev 1008926ef7 @hanzo/svelte 1.0.0 — the Svelte backend, on its own
Extracted from @hanzo/ui pkg/ui/src/backends/svelte with its history. It lived
inside a React component library, which meant every consumer of @hanzo/ui
resolved svelte whether they rendered a single Svelte component or not, and the
package declared peer svelte>=5 against a dev svelte ^4.2.20 — two answers to
one question.

Three runtime dependencies, all load-bearing: class-variance-authority for the
variants the components already used, and clsx + tailwind-merge behind cn. The
cn helper is vendored (17 lines) rather than imported back from @hanzo/ui,
because depending on the package this was extracted from would undo the split.
No design-system runtime, no icon pack, no CSS-in-JS.

svelte-check: 50 files, 0 errors.

Co-authored-by: Hanzo Dev <[email protected]>
2026-07-28 12:28:39 -07:00

48 lines
1.4 KiB
Svelte

<!--
SelectTrigger — opens the listbox and shows the current value (usually via
SelectValue in its slot). Standard-token styling parallels the shadcn backend;
trailing chevron.
-->
<script lang="ts">
import { getSelect } from './internal/context'
import { cn } from './core/cn'
let className: string | undefined = undefined
export { className as class }
export let disabled = false
const { toggle, open, contentId, triggerId } = getSelect('SelectTrigger')
</script>
<button
type="button"
id={triggerId}
role="combobox"
aria-haspopup="listbox"
aria-expanded={$open}
aria-controls={contentId}
{disabled}
data-slot="select-trigger"
data-state={$open ? 'open' : 'closed'}
class={cn(
'flex h-9 w-fit items-center justify-between gap-2 whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm text-foreground shadow-xs transition-colors outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
on:click={() => !disabled && toggle()}
{...$$restProps}
>
<slot />
<svg
viewBox="0 0 24 24"
class="size-4 opacity-50"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m6 9 6 6 6-6" />
</svg>
</button>