Skip to content

Commit

Permalink
expose additional events (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Oct 19, 2023
1 parent c410155 commit e788665
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-avocados-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

expose additional events
6 changes: 5 additions & 1 deletion src/lib/bits/select/components/SelectContent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use:melt={builder}
{...$$restProps}
on:m-pointerleave={dispatch}
on:keydown
>
<slot {builder} />
</div>
Expand All @@ -50,6 +51,7 @@
use:melt={builder}
{...$$restProps}
on:m-pointerleave={dispatch}
on:keydown
>
<slot {builder} />
</div>
Expand All @@ -60,6 +62,7 @@
use:melt={builder}
{...$$restProps}
on:m-pointerleave={dispatch}
on:keydown
>
<slot {builder} />
</div>
Expand All @@ -70,12 +73,13 @@
use:melt={builder}
{...$$restProps}
on:m-pointerleave={dispatch}
on:keydown
>
<slot {builder} />
</div>
{:else if $open}
{@const builder = $menu}
<div use:melt={builder} {...$$restProps} on:m-pointerleave={dispatch}>
<div use:melt={builder} {...$$restProps} on:m-pointerleave={dispatch} on:keydown>
<slot {builder} />
</div>
{/if}
11 changes: 10 additions & 1 deletion src/lib/bits/select/components/SelectItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@
<slot builder={$option({ value, disabled, label })} />
{:else}
{@const builder = $option({ value, disabled, label })}
<div use:melt={builder} {...$$restProps} on:m-click={dispatch} on:m-pointermove={dispatch}>
<div
use:melt={builder}
{...$$restProps}
on:m-click={dispatch}
on:m-pointermove={dispatch}
on:focusin
on:keydown
on:focusout
on:pointerleave
>
<slot {builder}>
{label ? label : value}
</slot>
Expand Down
12 changes: 11 additions & 1 deletion src/lib/bits/select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import type {
Transition,
TransitionProps
} from "$lib/internal/index.js";
import type { HTMLAttributes, HTMLButtonAttributes, HTMLInputAttributes } from "svelte/elements";
import type {
EventHandler,
HTMLAttributes,
HTMLButtonAttributes,
HTMLInputAttributes
} from "svelte/elements";
import type { CustomEventHandler } from "$lib/index.js";

type Props = Expand<
Expand Down Expand Up @@ -51,6 +56,10 @@ type ArrowProps = Expand<
type ItemEvents<T extends Element = HTMLDivElement> = {
click: CustomEventHandler<MouseEvent, T>;
pointermove: CustomEventHandler<PointerEvent, T>;
focusin: EventHandler<FocusEvent, T>;
keydown: EventHandler<KeyboardEvent, T>;
focusout: EventHandler<FocusEvent, T>;
pointerleave: EventHandler<PointerEvent, T>;
};

type TriggerEvents<T extends Element = HTMLButtonElement> = {
Expand All @@ -63,6 +72,7 @@ type LabelEvents<T extends Element = HTMLSpanElement> = {
};
type ContentEvents<T extends Element = HTMLDivElement> = {
pointerleave: CustomEventHandler<PointerEvent, T>;
keydown: EventHandler<KeyboardEvent, T>;
};

export type {
Expand Down

0 comments on commit e788665

Please sign in to comment.