Skip to content

Commit

Permalink
fix: improve backdrop click accuracy
Browse files Browse the repository at this point in the history
  • Loading branch information
igordanchenko committed Aug 10, 2024
1 parent e44b034 commit d9ef276
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/components/useSensors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export default function useSensors() {
} else if (
(deltaY > 50 && deltaY > 1.2 * deltaX && ((closeOnPullUp && dy < 0) || (closeOnPullDown && dy > 0))) ||
(closeOnBackdropClick &&
activePointer.current.target instanceof HTMLElement &&
activePointer.current.target.className.split(" ").includes(cssClass("slide")))
activePointer.current.target instanceof Element &&
Array.from(activePointer.current.target.classList).some((className) =>
[cssClass("slide"), cssClass("portal")].includes(className),
))
) {
close();
}
Expand Down
16 changes: 14 additions & 2 deletions test/Lightbox.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe("Lightbox", () => {
expectCurrentSlideToBe(1);
});

it("supports close on pull up", async () => {
it("supports closeOnPullUp", async () => {
const user = userEvent.setup();

renderLightbox();
Expand All @@ -104,7 +104,7 @@ describe("Lightbox", () => {
await expectLightboxToBeClosed();
});

it("supports close on pull down", async () => {
it("supports closeOnPullDown", async () => {
const user = userEvent.setup();

renderLightbox();
Expand All @@ -113,6 +113,18 @@ describe("Lightbox", () => {
await expectLightboxToBeClosed();
});

it("supports closeOnBackdropClick", async () => {
const user = userEvent.setup();

renderLightbox();
await user.click(querySelector(".yarll__portal")!);
await expectLightboxToBeClosed();

renderLightbox();
await user.click(querySelector(".yarll__slide")!);
await expectLightboxToBeClosed();
});

it("cancels multi-touch gestures", async () => {
const user = userEvent.setup();

Expand Down

0 comments on commit d9ef276

Please sign in to comment.