Skip to content

Commit

Permalink
fix: exported select prop type (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Dec 6, 2023
1 parent 946d16b commit ddd2a87
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-pianos-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

fix: exported `SelectProps` type
2 changes: 1 addition & 1 deletion src/components/demos/select-demo.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
];
</script>

<Select.Root>
<Select.Root items={themes}>
<Select.Trigger
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"
aria-label="Select a theme"
Expand Down
7 changes: 7 additions & 0 deletions src/content/api-reference/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ export const root: APISchema<Select.Props> = {
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 }
Expand Down
13 changes: 12 additions & 1 deletion src/lib/bits/select/_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = {
value: T;
label?: string;
}[];

type Props<T = unknown, Multiple extends boolean = false> = Expand<
OmitFloating<Omit<CreateSelectProps, "selected" | "defaultSelected" | "onSelectedChange">> & {
/**
Expand Down Expand Up @@ -36,9 +41,15 @@ type Props<T = unknown, Multiple extends boolean = false> = Expand<
onOpenChange?: OnChangeFn<boolean>;

/**
*
* 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<T>;
}
>;

Expand Down

0 comments on commit ddd2a87

Please sign in to comment.