Skip to content

Commit

Permalink
fix: select events (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte authored Aug 21, 2023
1 parent c646c47 commit 9f21863
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/twelve-tables-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bits-ui": patch
---

Fix: Select events
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
on:m-keydown
on:m-pointerleave
on:m-pointermove
on:m-keydown
{...disabledAttrs(disabled)}
>
<slot {builder} />
Expand Down
22 changes: 8 additions & 14 deletions src/lib/bits/context-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,19 @@ type ArrowProps = Expand<
> &
HTMLDivAttributes;

type CheckboxItemEvents = {
"m-click": DivEventHandler<MouseEvent>;
"m-keydown": DivEventHandler<KeyboardEvent>;
};

type ItemEvents = {
"m-click": DivEventHandler<MouseEvent>;
"m-keydown": DivEventHandler<KeyboardEvent>;
"m-focusin": DivEventHandler<FocusEvent>;
"m-focusout": DivEventHandler<FocusEvent>;
"m-pointerdown": DivEventHandler<MouseEvent>;
"m-pointerleave": DivEventHandler<MouseEvent>;
"m-pointermove": DivEventHandler<MouseEvent>;
};

type RadioItemEvents = {
"m-click": DivEventHandler<MouseEvent>;
"m-keydown": DivEventHandler<KeyboardEvent>;
};

type SubTriggerEvents = {
"m-click": DivEventHandler<MouseEvent>;
"m-keydown": DivEventHandler<KeyboardEvent>;
};
type CheckboxItemEvents = ItemEvents;
type RadioItemEvents = ItemEvents;
type SubTriggerEvents = Omit<ItemEvents, "m-pointerdown">;

type TriggerEvents = {
"m-pointerdown": DivEventHandler<MouseEvent>;
Expand Down
7 changes: 6 additions & 1 deletion src/lib/bits/dropdown-menu/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,16 @@ type ArrowProps = Expand<
type ItemEvents = {
"m-click": DivEventHandler<MouseEvent>;
"m-keydown": DivEventHandler<KeyboardEvent>;
"m-focusin": DivEventHandler<FocusEvent>;
"m-focusout": DivEventHandler<FocusEvent>;
"m-pointerdown": DivEventHandler<MouseEvent>;
"m-pointerleave": DivEventHandler<MouseEvent>;
"m-pointermove": DivEventHandler<MouseEvent>;
};

type CheckboxItemEvents = ItemEvents;
type RadioItemEvents = ItemEvents;
type SubTriggerEvents = ItemEvents;
type SubTriggerEvents = Omit<ItemEvents, "m-pointerdown">;

type TriggerEvents = {
"m-click": ButtonEventHandler<MouseEvent>;
Expand Down
14 changes: 11 additions & 3 deletions src/lib/bits/select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
TransitionProps
} from "$internal/index.js";
import type { HTMLAttributes, HTMLButtonAttributes, HTMLInputAttributes } from "svelte/elements";
import type { ButtonEventHandler, DivEventHandler } from "$lib/index.js";
import type { ButtonEventHandler, DivEventHandler, MEventHandler } from "$lib/index.js";

type Props = Expand<
OmitOpen<OmitValue<Omit<CreateSelectProps, "defaultValueLabel">>> & {
Expand Down Expand Up @@ -53,15 +53,23 @@ type ArrowProps = Expand<
type ItemEvents = {
"m-click": DivEventHandler<MouseEvent>;
"m-keydown": DivEventHandler<KeyboardEvent>;
"m-focusin": DivEventHandler<FocusEvent>;
"m-focusout": DivEventHandler<FocusEvent>;
"m-pointerleave": DivEventHandler<MouseEvent>;
"m-pointermove": DivEventHandler<MouseEvent>;
};

type TriggerEvents = {
"m-click": ButtonEventHandler<MouseEvent>;
"m-keydown": ButtonEventHandler<KeyboardEvent>;
};

type LabelEvents = SelectComponentEvents["label"];
type ContentEvents = SelectComponentEvents["menu"];
type LabelEvents = {
"m-click": MEventHandler<MouseEvent, HTMLSpanElement>;
};
type ContentEvents = {
"m-keydown": DivEventHandler<KeyboardEvent>;
};

export type {
Props,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/helpers/event-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export type DivEventHandler<T extends Event = Event> = T & {
export type SpanEventHandler<T extends Event = Event> = T & {
currentTarget: EventTarget & HTMLSpanElement;
};

export type MEventHandler<T extends Event = Event, M extends Element = Element> = T & {
currentTarget: EventTarget & M;
};

0 comments on commit 9f21863

Please sign in to comment.