Skip to content

Commit ddd2a87

Browse files
authored
fix: exported select prop type (#214)
1 parent 946d16b commit ddd2a87

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

.changeset/new-pianos-compete.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
fix: exported `SelectProps` type

src/components/demos/select-demo.svelte

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
];
1212
</script>
1313

14-
<Select.Root>
14+
<Select.Root items={themes}>
1515
<Select.Trigger
1616
class="inline-flex h-input w-[296px] items-center rounded-9px border border-border-input bg-background px-[11px] text-sm transition-colors placeholder:text-foreground-alt/50 focus:outline-none focus:ring-2 focus:ring-foreground focus:ring-offset-2 focus:ring-offset-background"
1717
aria-label="Select a theme"

src/content/api-reference/select.ts

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ export const root: APISchema<Select.Props> = {
102102
default: C.TRUE,
103103
description:
104104
"Whether or not to enable typeahead functionality. When enabled, the user can type to navigate to menu items."
105+
},
106+
items: {
107+
type: {
108+
type: "Selected[]",
109+
definition: "Array<{ value: T; label?: string }>"
110+
},
111+
description: "An array of items to add type-safety to the `onSelectedChange` callback."
105112
}
106113
},
107114
slotProps: { ids: idsSlotProp }

src/lib/bits/select/_types.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import type { CreateSelectProps, SelectOptionProps } from "@melt-ui/svelte";
77
import type { AsChild, Expand, OmitFloating, OnChangeFn } from "$lib/internal/index.js";
88
import type { ContentProps, ArrowProps } from "$lib/bits/floating/_types.js";
99

10+
type Items<T> = {
11+
value: T;
12+
label?: string;
13+
}[];
14+
1015
type Props<T = unknown, Multiple extends boolean = false> = Expand<
1116
OmitFloating<Omit<CreateSelectProps, "selected" | "defaultSelected" | "onSelectedChange">> & {
1217
/**
@@ -36,9 +41,15 @@ type Props<T = unknown, Multiple extends boolean = false> = Expand<
3641
onOpenChange?: OnChangeFn<boolean>;
3742

3843
/**
39-
*
44+
* Whether or not multiple values can be selected.
4045
*/
4146
multiple?: Multiple;
47+
48+
/**
49+
* Optional array of items to add type-safety to the
50+
* `onSelectedChange` callback and `selected` prop.
51+
*/
52+
items?: Items<T>;
4253
}
4354
>;
4455

0 commit comments

Comments
 (0)