From 9f2186330eafe6dde437543df3e9f09beac3fabf Mon Sep 17 00:00:00 2001
From: Hunter Johnston <64506580+huntabyte@users.noreply.github.com>
Date: Mon, 21 Aug 2023 18:43:24 -0400
Subject: [PATCH] fix: select events (#71)
---
.changeset/twelve-tables-kick.md | 5 +++++
.../components/ContextMenuSubTrigger.svelte | 1 +
src/lib/bits/context-menu/types.ts | 22 +++++++------------
src/lib/bits/dropdown-menu/types.ts | 7 +++++-
src/lib/bits/select/types.ts | 14 +++++++++---
src/lib/helpers/event-handlers.ts | 4 ++++
6 files changed, 35 insertions(+), 18 deletions(-)
create mode 100644 .changeset/twelve-tables-kick.md
diff --git a/.changeset/twelve-tables-kick.md b/.changeset/twelve-tables-kick.md
new file mode 100644
index 000000000..74afb3799
--- /dev/null
+++ b/.changeset/twelve-tables-kick.md
@@ -0,0 +1,5 @@
+---
+"bits-ui": patch
+---
+
+Fix: Select events
diff --git a/src/lib/bits/context-menu/components/ContextMenuSubTrigger.svelte b/src/lib/bits/context-menu/components/ContextMenuSubTrigger.svelte
index 3356cc277..8d1b3c934 100644
--- a/src/lib/bits/context-menu/components/ContextMenuSubTrigger.svelte
+++ b/src/lib/bits/context-menu/components/ContextMenuSubTrigger.svelte
@@ -30,6 +30,7 @@
on:m-keydown
on:m-pointerleave
on:m-pointermove
+ on:m-keydown
{...disabledAttrs(disabled)}
>
diff --git a/src/lib/bits/context-menu/types.ts b/src/lib/bits/context-menu/types.ts
index 0749d34a4..5238f193d 100644
--- a/src/lib/bits/context-menu/types.ts
+++ b/src/lib/bits/context-menu/types.ts
@@ -92,25 +92,19 @@ type ArrowProps = Expand<
> &
HTMLDivAttributes;
-type CheckboxItemEvents = {
- "m-click": DivEventHandler;
- "m-keydown": DivEventHandler;
-};
-
type ItemEvents = {
"m-click": DivEventHandler;
"m-keydown": DivEventHandler;
+ "m-focusin": DivEventHandler;
+ "m-focusout": DivEventHandler;
+ "m-pointerdown": DivEventHandler;
+ "m-pointerleave": DivEventHandler;
+ "m-pointermove": DivEventHandler;
};
-type RadioItemEvents = {
- "m-click": DivEventHandler;
- "m-keydown": DivEventHandler;
-};
-
-type SubTriggerEvents = {
- "m-click": DivEventHandler;
- "m-keydown": DivEventHandler;
-};
+type CheckboxItemEvents = ItemEvents;
+type RadioItemEvents = ItemEvents;
+type SubTriggerEvents = Omit;
type TriggerEvents = {
"m-pointerdown": DivEventHandler;
diff --git a/src/lib/bits/dropdown-menu/types.ts b/src/lib/bits/dropdown-menu/types.ts
index 0c089c9ed..db3bce391 100644
--- a/src/lib/bits/dropdown-menu/types.ts
+++ b/src/lib/bits/dropdown-menu/types.ts
@@ -102,11 +102,16 @@ type ArrowProps = Expand<
type ItemEvents = {
"m-click": DivEventHandler;
"m-keydown": DivEventHandler;
+ "m-focusin": DivEventHandler;
+ "m-focusout": DivEventHandler;
+ "m-pointerdown": DivEventHandler;
+ "m-pointerleave": DivEventHandler;
+ "m-pointermove": DivEventHandler;
};
type CheckboxItemEvents = ItemEvents;
type RadioItemEvents = ItemEvents;
-type SubTriggerEvents = ItemEvents;
+type SubTriggerEvents = Omit;
type TriggerEvents = {
"m-click": ButtonEventHandler;
diff --git a/src/lib/bits/select/types.ts b/src/lib/bits/select/types.ts
index 932d8f998..e1257ffd9 100644
--- a/src/lib/bits/select/types.ts
+++ b/src/lib/bits/select/types.ts
@@ -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>> & {
@@ -53,6 +53,10 @@ type ArrowProps = Expand<
type ItemEvents = {
"m-click": DivEventHandler;
"m-keydown": DivEventHandler;
+ "m-focusin": DivEventHandler;
+ "m-focusout": DivEventHandler;
+ "m-pointerleave": DivEventHandler;
+ "m-pointermove": DivEventHandler;
};
type TriggerEvents = {
@@ -60,8 +64,12 @@ type TriggerEvents = {
"m-keydown": ButtonEventHandler;
};
-type LabelEvents = SelectComponentEvents["label"];
-type ContentEvents = SelectComponentEvents["menu"];
+type LabelEvents = {
+ "m-click": MEventHandler;
+};
+type ContentEvents = {
+ "m-keydown": DivEventHandler;
+};
export type {
Props,
diff --git a/src/lib/helpers/event-handlers.ts b/src/lib/helpers/event-handlers.ts
index 17366191a..ecc9ee006 100644
--- a/src/lib/helpers/event-handlers.ts
+++ b/src/lib/helpers/event-handlers.ts
@@ -9,3 +9,7 @@ export type DivEventHandler = T & {
export type SpanEventHandler = T & {
currentTarget: EventTarget & HTMLSpanElement;
};
+
+export type MEventHandler = T & {
+ currentTarget: EventTarget & M;
+};