Skip to content

Commit

Permalink
feat: expose isSelected slot prop to Select.Item (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Jan 19, 2024
1 parent ef74ed8 commit 2efac48
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-pots-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": minor
---

feat: expose `isSelected` slot prop from `Select.Item`
8 changes: 7 additions & 1 deletion src/content/api-reference/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,13 @@ export const item: APISchema<Select.ItemProps> = {
},
...domElProps("HTMLDivElement")
},
slotProps: { ...builderAndAttrsSlotProps },
slotProps: {
isSelected: {
type: C.BOOLEAN,
description: "Whether or not the item is selected."
},
...builderAndAttrsSlotProps
},
dataAttributes: [
{
name: "state",
Expand Down
6 changes: 4 additions & 2 deletions src/lib/bits/select/components/select-item.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const {
elements: { option: item },
helpers: { isSelected: isSelectedStore },
getAttrs
} = setItemCtx(value);
Expand All @@ -23,12 +24,13 @@
$: builder = $item({ value, disabled, label });
$: Object.assign(builder, attrs);
$: isSelected = $isSelectedStore(value);
</script>

<!-- svelte-ignore a11y-no-static-element-interactions / applied by melt's builder-->

{#if asChild}
<slot {builder} />
<slot {builder} {isSelected} />
{:else}
<div
bind:this={el}
Expand All @@ -41,7 +43,7 @@
on:focusout
on:pointerleave
>
<slot {builder}>
<slot {builder} {isSelected}>
{label ? label : value}
</slot>
</div>
Expand Down

0 comments on commit 2efac48

Please sign in to comment.