From ddd2a873300f4305037f94e734ffd07f8f9e09b8 Mon Sep 17 00:00:00 2001 From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com> Date: Tue, 5 Dec 2023 19:38:08 -0500 Subject: [PATCH] fix: exported select prop type (#214) --- .changeset/new-pianos-compete.md | 5 +++++ src/components/demos/select-demo.svelte | 2 +- src/content/api-reference/select.ts | 7 +++++++ src/lib/bits/select/_types.ts | 13 ++++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .changeset/new-pianos-compete.md diff --git a/.changeset/new-pianos-compete.md b/.changeset/new-pianos-compete.md new file mode 100644 index 000000000..4782abac4 --- /dev/null +++ b/.changeset/new-pianos-compete.md @@ -0,0 +1,5 @@ +--- +"bits-ui": patch +--- + +fix: exported `SelectProps` type diff --git a/src/components/demos/select-demo.svelte b/src/components/demos/select-demo.svelte index 967c3c6ec..cea4c4472 100644 --- a/src/components/demos/select-demo.svelte +++ b/src/components/demos/select-demo.svelte @@ -11,7 +11,7 @@ ]; - + = { default: C.TRUE, description: "Whether or not to enable typeahead functionality. When enabled, the user can type to navigate to menu items." + }, + items: { + type: { + type: "Selected[]", + definition: "Array<{ value: T; label?: string }>" + }, + description: "An array of items to add type-safety to the `onSelectedChange` callback." } }, slotProps: { ids: idsSlotProp } diff --git a/src/lib/bits/select/_types.ts b/src/lib/bits/select/_types.ts index e1b1cdf7b..ef3449749 100644 --- a/src/lib/bits/select/_types.ts +++ b/src/lib/bits/select/_types.ts @@ -7,6 +7,11 @@ import type { CreateSelectProps, SelectOptionProps } from "@melt-ui/svelte"; import type { AsChild, Expand, OmitFloating, OnChangeFn } from "$lib/internal/index.js"; import type { ContentProps, ArrowProps } from "$lib/bits/floating/_types.js"; +type Items = { + value: T; + label?: string; +}[]; + type Props = Expand< OmitFloating> & { /** @@ -36,9 +41,15 @@ type Props = Expand< onOpenChange?: OnChangeFn; /** - * + * Whether or not multiple values can be selected. */ multiple?: Multiple; + + /** + * Optional array of items to add type-safety to the + * `onSelectedChange` callback and `selected` prop. + */ + items?: Items; } >;