bits-ui 2.12.0 → 2.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@
15
15
  children,
16
16
  child,
17
17
  onSelect = noop,
18
+ openDelay = 100,
18
19
  ...restProps
19
20
  }: MenuSubTriggerProps = $props();
20
21
 
@@ -26,6 +27,7 @@
26
27
  () => ref,
27
28
  (v) => (ref = v)
28
29
  ),
30
+ openDelay: boxWith(() => openDelay),
29
31
  });
30
32
 
31
33
  const mergedProps = $derived(mergeProps(restProps, subTriggerState.props));
@@ -1,4 +1,4 @@
1
- import { DOMContext, type ReadableBoxedValues, type WritableBoxedValues } from "svelte-toolbelt";
1
+ import { DOMContext, type ReadableBoxedValues, type WritableBoxedValues, type ReadableBox } from "svelte-toolbelt";
2
2
  import { Context } from "runed";
3
3
  import { CustomEventDispatcher } from "../../internal/events.js";
4
4
  import type { AnyFn, BitsFocusEvent, BitsKeyboardEvent, BitsMouseEvent, BitsPointerEvent, OnChangeFn, RefAttachment, WithRefOpts } from "../../internal/types.js";
@@ -38,7 +38,7 @@ export declare class MenuMenuState {
38
38
  readonly opts: MenuMenuStateOpts;
39
39
  readonly root: MenuRootState;
40
40
  readonly parentMenu: MenuMenuState | null;
41
- contentId: import("svelte-toolbelt").ReadableBox<string>;
41
+ contentId: ReadableBox<string>;
42
42
  contentNode: HTMLElement | null;
43
43
  triggerNode: HTMLElement | null;
44
44
  constructor(opts: MenuMenuStateOpts, root: MenuRootState, parentMenu: MenuMenuState | null);
@@ -157,6 +157,7 @@ export declare class MenuItemState {
157
157
  };
158
158
  }
159
159
  interface MenuSubTriggerStateOpts extends MenuItemSharedStateOpts, Pick<MenuItemStateOpts, "onSelect"> {
160
+ openDelay: ReadableBox<number>;
160
161
  }
161
162
  export declare class MenuSubTriggerState {
162
163
  #private;
@@ -510,7 +510,7 @@ export class MenuSubTriggerState {
510
510
  this.#openTimer = this.content.domContext.setTimeout(() => {
511
511
  this.submenu.onOpen();
512
512
  this.#clearOpenTimer();
513
- }, 100);
513
+ }, this.opts.openDelay.current);
514
514
  }
515
515
  }
516
516
  onpointerleave(e) {
@@ -149,8 +149,20 @@ export type MenuSubContentPropsWithoutHTML = Expand<WithChildNoChildrenSnippetPr
149
149
  export type MenuSubContentProps = MenuSubContentPropsWithoutHTML & Without<BitsPrimitiveDivAttributes, MenuSubContentPropsWithoutHTML>;
150
150
  export type MenuSubContentStaticPropsWithoutHTML = Expand<WithChildNoChildrenSnippetProps<Omit<PopperLayerStaticProps, "content" | "preventScroll"> & _SharedMenuContentProps, StaticContentSnippetProps>>;
151
151
  export type MenuSubContentStaticProps = MenuSubContentStaticPropsWithoutHTML & Without<BitsPrimitiveDivAttributes, MenuSubContentStaticPropsWithoutHTML>;
152
- export type MenuSubTriggerPropsWithoutHTML = Omit<MenuItemPropsWithoutHTML, "closeOnSelect">;
153
- export type MenuSubTriggerProps = Omit<MenuItemProps, "closeOnSelect">;
152
+ export type MenuSubTriggerPropsWithoutHTML = Omit<MenuItemPropsWithoutHTML, "closeOnSelect"> & {
153
+ /**
154
+ * The amount of time in ms from when the mouse enters the subtrigger until
155
+ * the submenu opens. This is useful for preventing the submenu from opening
156
+ * as a user is moving their mouse through the menu without a true intention to open that
157
+ * submenu.
158
+ *
159
+ * To disable the behavior, set it to `0`.
160
+ *
161
+ * @default 100
162
+ */
163
+ openDelay?: number;
164
+ };
165
+ export type MenuSubTriggerProps = MenuSubTriggerPropsWithoutHTML & Without<BitsPrimitiveDivAttributes, MenuSubTriggerPropsWithoutHTML>;
154
166
  export type MenuSeparatorPropsWithoutHTML = WithChild;
155
167
  export type MenuSeparatorProps = MenuSeparatorPropsWithoutHTML & Without<BitsPrimitiveDivAttributes, MenuSeparatorPropsWithoutHTML>;
156
168
  export type MenuArrowPropsWithoutHTML = ArrowPropsWithoutHTML;
@@ -193,6 +193,8 @@ function isValidEvent(e, node) {
193
193
  const targetIsContextMenuTrigger = Boolean(target.closest(`[${CONTEXT_MENU_TRIGGER_ATTR}]`));
194
194
  if ("button" in e && e.button > 0 && !targetIsContextMenuTrigger)
195
195
  return false;
196
+ if ("button" in e && e.button === 0 && targetIsContextMenuTrigger)
197
+ return true;
196
198
  const nodeIsContextMenu = Boolean(node.closest(`[${CONTEXT_MENU_CONTENT_ATTR}]`));
197
199
  if (targetIsContextMenuTrigger && nodeIsContextMenu)
198
200
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "2.12.0",
3
+ "version": "2.13.1",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",