Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions e2e/VList.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,26 @@ test.describe("smoke", () => {
).toBeVisible();
});

// test("horizontally scrollable (writing-mode: vertical-rl)", async ({ page }) => {
// await page.goto(storyUrl("basics-vlist--rtl"));

// const component = page.locator(
// '*[style*="writing-mode"]'
// ) as ScrollableLocator;

// // check if start is displayed
// const first = component.getByText("列 0", { exact: true });
// await expect(first).toBeVisible();
// expect(await relativeRight(component, first)).toEqual(0);

// // scroll to the end
// await scrollToLeft(component);

// // check if the end is displayed
// await expect(
// component.getByText("列 999", { exact: true })
// ).toBeVisible();
// });
test("horizontally scrollable (writing-mode: vertical-rl)", async ({ page }) => {
await page.goto(storyUrl("basics-vlist--rtl"));

const component = page.locator(
'*[style*="writing-mode"]'
) as ScrollableLocator;

// check if start is displayed
const first = component.getByText("列 0", { exact: true });
await expect(first).toBeVisible();
expect(await relativeRight(component, first)).toEqual(0);

// scroll to the end
await scrollToLeft(component);

// check if the end is displayed
await expect(
component.getByText("列 999", { exact: true })
).toBeVisible();
});

test("display: none", async ({ page }) => {
await page.goto(storyUrl("basics-vlist--default"));
Expand Down
24 changes: 12 additions & 12 deletions e2e/Virtualizer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,22 @@ test("overflow", async ({ page }) => {
}
});

// test("reverse with flex-direction: column-reverse", async ({ page }) => {
// await page.goto(storyUrl("basics-virtualizer--inverted"));
test("reverse with flex-direction: column-reverse", async ({ page }) => {
await page.goto(storyUrl("basics-virtualizer--inverted"));

// const component = await getScrollable(page);
const component = await getScrollable(page);

// // check if start is displayed
// const first = component.getByText("0", { exact: true });
// await expect(first).toBeVisible();
// expect(await relativeBottom(component, first)).toEqual(0);
// check if start is displayed
const first = component.getByText("0", { exact: true });
await expect(first).toBeVisible();
expect(await relativeBottom(component, first)).toEqual(0);

// // scroll to the end
// await scrollToTop(component);
// scroll to the end
await scrollToTop(component);

// // check if the end is displayed
// await expect(component.getByText("999", { exact: true })).toBeVisible();
// });
// check if the end is displayed
await expect(component.getByText("999", { exact: true })).toBeVisible();
});

test.describe("aligned to bottom", () => {
test("reverse", async ({ page }) => {
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineConfig({
projects: [
{
name: "chromium",
use: { ...devices["Desktop Chrome"] },
use: { ...devices["Desktop Chrome"], deviceScaleFactor: 1.5 },
grepInvert: new RegExp(String.raw`${IOS_SPECS}`),
},
{
Expand Down
28 changes: 25 additions & 3 deletions src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,31 @@ export const createScroller = (
$observe(viewport) {
viewportElement = viewport;

if (isHorizontal) {
isNegative = getComputedStyle(viewport).direction === "rtl";
}
const clean = store.$subscribe(UPDATE_SIZE_EVENT, () => {
// Detect overflowed direction after the initial viewport measurement
const viewportSize = store.$getViewportSize();
if (viewportSize) {
const prev = viewport[scrollOffsetKey];

const dummy = getCurrentDocument(viewport).createElement("div");
// Append element larger than the viewportSize to force overflow.
dummy.style.cssText = `visibility:hidden;min-${
isHorizontal ? "width" : "height"
}:${viewportSize + 9}px`;
viewport.appendChild(dummy);

// Set positive value to scrollTop/scrollLeft to check if the range is negative or positive.
// However the value can be positive value even if it is negative range (e.g. 0.6666px in Windows Chrome), so we use `< 1` here.
// For similar reason, the appended element's size must be larger than viewportSize + 1px, to take subpixels into account.
viewport[scrollOffsetKey] = 1;
isNegative = viewport[scrollOffsetKey] < 1;
viewport.removeChild(dummy);

viewport[scrollOffsetKey] = prev;

clean();
}
});

scrollObserver = createScrollObserver(
store,
Expand Down
4 changes: 2 additions & 2 deletions stories/react/basics/VList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const Rtl: StoryObj = {
);
})}
</VList>
{/* <VList
<VList
style={{ width: "100%", height: 200, writingMode: "vertical-rl" }}
horizontal
>
Expand All @@ -124,7 +124,7 @@ export const Rtl: StoryObj = {
</div>
);
})}
</VList> */}
</VList>
</div>
);
},
Expand Down
38 changes: 19 additions & 19 deletions stories/react/basics/Virtualizer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,25 @@ export const Reverse: StoryObj = {
},
};

// export const Inverted: StoryObj = {
// render: () => {
// return (
// <div
// style={{
// height: "100vh",
// overflowY: "auto",
// // opt out browser's scroll anchoring on header/footer because it will conflict to scroll anchoring of virtualizer
// overflowAnchor: "none",
// // apply column-reverse to reverse scroll direction
// display: "flex",
// flexDirection: "column-reverse",
// }}
// >
// <Virtualizer>{createRows(1000)}</Virtualizer>
// </div>
// );
// },
// };
export const Inverted: StoryObj = {
render: () => {
return (
<div
style={{
height: "100vh",
overflowY: "auto",
// opt out browser's scroll anchoring on header/footer because it will conflict to scroll anchoring of virtualizer
overflowAnchor: "none",
// apply column-reverse to reverse scroll direction
display: "flex",
flexDirection: "column-reverse",
}}
>
<Virtualizer>{createRows(1000)}</Virtualizer>
</div>
);
},
};

export const AlignBottom: StoryObj = {
render: () => {
Expand Down
Loading