bits-ui 2.11.0 → 2.11.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.
@@ -24,7 +24,14 @@
24
24
  });
25
25
 
26
26
  const mergedProps = $derived(
27
- mergeProps(restProps, triggerState.props, { style: { pointerEvents: "auto" } })
27
+ mergeProps(
28
+ restProps,
29
+ triggerState.props,
30
+ { style: { pointerEvents: "auto" } },
31
+ {
32
+ style: restProps.style,
33
+ }
34
+ )
28
35
  );
29
36
  </script>
30
37
 
@@ -13,6 +13,7 @@ import { DOMTypeahead } from "../../internal/dom-typeahead.svelte.js";
13
13
  import { RovingFocusGroup } from "../../internal/roving-focus-group.js";
14
14
  import { GraceArea } from "../../internal/grace-area.svelte.js";
15
15
  import { OpenChangeComplete } from "../../internal/open-change-complete.js";
16
+ import { getTopMostDismissableLayer } from "../utilities/dismissible-layer/use-dismissable-layer.svelte.js";
16
17
  export const CONTEXT_MENU_TRIGGER_ATTR = "data-context-menu-trigger";
17
18
  const MenuRootContext = new Context("Menu.Root");
18
19
  const MenuMenuContext = new Context("Menu.Root | Menu.Sub");
@@ -880,6 +881,15 @@ export class ContextMenuTriggerState {
880
881
  oncontextmenu(e) {
881
882
  if (e.defaultPrevented || this.opts.disabled.current)
882
883
  return;
884
+ const topMostLayer = getTopMostDismissableLayer();
885
+ if (topMostLayer) {
886
+ const topLayerRef = topMostLayer[0].opts.ref.current;
887
+ const topLayerRefContainsTrigger = topLayerRef?.contains(this.opts.ref.current);
888
+ if (!topLayerRefContainsTrigger &&
889
+ !topLayerRef?.hasAttribute?.("data-context-menu-content")) {
890
+ return;
891
+ }
892
+ }
883
893
  this.#clearLongPressTimer();
884
894
  this.#handleOpen(e);
885
895
  e.preventDefault();
@@ -1,5 +1,5 @@
1
- import { type WritableBox, type ReadableBoxedValues } from "svelte-toolbelt";
2
- import type { DismissibleLayerImplProps } from "./types.js";
1
+ import { type ReadableBox, type WritableBox, type ReadableBoxedValues } from "svelte-toolbelt";
2
+ import type { DismissibleLayerImplProps, InteractOutsideBehaviorType } from "./types.js";
3
3
  interface DismissibleLayerStateOpts extends ReadableBoxedValues<Required<Omit<DismissibleLayerImplProps, "children" | "ref">>> {
4
4
  ref: WritableBox<HTMLElement | null>;
5
5
  }
@@ -13,6 +13,7 @@ export declare class DismissibleLayerState {
13
13
  onblurcapture: () => void;
14
14
  };
15
15
  }
16
+ export declare function getTopMostDismissableLayer(layersArr?: [DismissibleLayerState, ReadableBox<InteractOutsideBehaviorType>][]): [DismissibleLayerState, ReadableBox<InteractOutsideBehaviorType>] | undefined;
16
17
  export type FocusOutsideEvent = CustomEvent<{
17
18
  originalEvent: FocusEvent;
18
19
  }>;
@@ -166,7 +166,9 @@ export class DismissibleLayerState {
166
166
  onblurcapture: this.#onblurcapture,
167
167
  };
168
168
  }
169
- function getTopMostLayer(layersArr) {
169
+ export function getTopMostDismissableLayer(layersArr = [
170
+ ...globalThis.bitsDismissableLayers,
171
+ ]) {
170
172
  return layersArr.findLast(([_, { current: behaviorType }]) => behaviorType === "close" || behaviorType === "ignore");
171
173
  }
172
174
  function isResponsibleLayer(node) {
@@ -177,7 +179,7 @@ function isResponsibleLayer(node) {
177
179
  * responsible for the outside interaction. Otherwise, we know that all layers defer so
178
180
  * the first layer is the responsible one.
179
181
  */
180
- const topMostLayer = getTopMostLayer(layersArr);
182
+ const topMostLayer = getTopMostDismissableLayer(layersArr);
181
183
  if (topMostLayer)
182
184
  return topMostLayer[0].opts.ref.current === node;
183
185
  const [firstLayerNode] = layersArr[0];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "2.11.0",
3
+ "version": "2.11.1",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",