Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(desktop): keep horizontal content scrolls from navigating history #28475

Closedshivamhwp(GitHub profile, opens in a new tab)wants to merge 26 commits intomain fromrefs/pull/28475/headopened View on GitHub

Showing 3 changed files with 105 additions and 50 deletions (loading 2).

x
0 of 3 viewed, 3 left
105 additions and 50 deletionsapps/web/src/components/HistorySwipeNavigation.browser.test.tsxModified
View file
@@ -1,74 +1,129 @@
import { describe, expect, it, vi } from "vite-plus/test";
​
-import { render } from "../../test/render";
+import { render, stubGlobal } from "../../test/render";
import { HistorySwipeNavigation } from "./HistorySwipeNavigation";
​
-const navigateHistory = vi.hoisted(() => vi.fn());
-vi.mock("../navigationHistory", () => ({ canNavigateHistory: () => true, navigateHistory }));
+type Scroller = "shadow" | "none" | "shadow-dialog";
+type Step = readonly [
+ event: number | "begin" | "end" | "show-scroller" | "gain-overflow",
+ after?: "remove" | "close-dialog",
+];
​
-function swipe(target: Element, deltaX: number) {
- for (const delta of [deltaX, 0]) {
- target.dispatchEvent(new WheelEvent("wheel", { deltaX: delta, bubbles: true, composed: true }));
- }
+function mountPanel(container: HTMLElement, scroller: Scroller, scrollLeft: number) {
+ const panel = container.appendChild(document.createElement("div"));
+ const root = scroller.startsWith("shadow") ? panel.attachShadow({ mode: "open" }) : panel;
+ const parent =
+ scroller === "shadow-dialog"
+ ? root.appendChild(Object.assign(document.createElement("div"), { role: "dialog" }))
+ : root;
+ const overflows = scroller === "shadow";
+ const viewport = parent.appendChild(document.createElement("div"));
+ viewport.style.cssText = `width: 200px; overflow-x: ${overflows ? "auto" : "visible"}`;
+ const content = viewport.appendChild(document.createElement("div"));
+ content.style.cssText = `height: 20px; width: ${overflows ? 1000 : 100}px`;