Skip to content

Commit

Permalink
Merge branch 'next' into next-escape-layer
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolzak authored Apr 18, 2024
2 parents b5af395 + 694fe14 commit 642835b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/bits-ui/src/lib/bits/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ export * as ToggleGroup from "./toggle-group/index.js";
export * as Toolbar from "./toolbar/index.js";
export * as Tooltip from "./tooltip/index.js";
export * as EscapeLayer from "./utilities/escape-layer/index.js";
export * as DismissableLayer from "./utilities/dismissable-layer/index.js";
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export class DismissableLayerState {
touchend: false,
click: false,
};
#isPointerDown = false;
#isPointerDownInside = false;
#isPointerDownOutside = false;
#isResponsibleLayer = false;
node: Box<HTMLElement | null>;
#documentObj: Document;
Expand All @@ -57,13 +56,15 @@ export class DismissableLayerState {
this.#interactOutsideStartProp = props.onInteractOutsideStart;
this.#interactOutsideProp = props.onInteractOutside;

layers.set(this, this.#behaviorType);
const unsubEvents = this.#addEventListeners();

onDestroy(() => {
unsubEvents();
this.#resetState.destroy();
this.#onInteractOutsideStart.destroy();
this.#onInteractOutside.destroy();
layers.delete(this);
});
}

Expand Down Expand Up @@ -113,7 +114,7 @@ export class DismissableLayerState {
*/
addEventListener(
this.#documentObj,
interactOutsideStartEvents,
interactOutsideEndEvents,
composeHandlers(this.#markNonInterceptedEvent, this.#onInteractOutside)
)
);
Expand All @@ -125,8 +126,7 @@ export class DismissableLayerState {
return;
this.#interactOutsideStartProp.value(e);
if (e.defaultPrevented) return;
this.#isPointerDownInside = true;
this.#isPointerDown = true;
this.#isPointerDownOutside = true;
}, 10);

#onInteractOutside = debounce((e: InteractOutsideEvent) => {
Expand All @@ -135,7 +135,7 @@ export class DismissableLayerState {
if (!this.#isResponsibleLayer || this.#isAnyEventIntercepted() || !isValidEvent(e, node))
return;
if (behaviorType !== "close" && behaviorType !== "defer-otherwise-close") return;
if (!this.#isPointerDown || this.#isPointerDownInside) return;
if (!this.#isPointerDownOutside) return;
this.#interactOutsideProp.value(e);
}, 10);

Expand All @@ -156,8 +156,7 @@ export class DismissableLayerState {
for (const eventType in this.#interceptedEvents) {
this.#interceptedEvents[eventType as InteractOutsideInterceptEventType] = false;
}
this.#isPointerDown = false;
this.#isPointerDownInside = false;
this.#isPointerDownOutside = false;
this.#isResponsibleLayer = false;
}, 20);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as DismissableLayer } from "./dismissable-layer.svelte";
export { default as Root } from "./dismissable-layer.svelte";

export type { DismissableLayerProps as Props } from "./types.js";

0 comments on commit 642835b

Please sign in to comment.