Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

a resize that cuts a pager settle short still ends it (#10419)

Christopher Chedeau43d485d835dc
diff --git a/.changeset/pager-resize-settle-ends.md b/.changeset/pager-resize-settle-ends.md
new file mode 100644
index 0000000000..06203921bb
--- /dev/null
+++ b/.changeset/pager-resize-settle-ends.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Carousel paging: a row that resizes while it settles back onto the page it left now hands back to native scrolling, instead of staying held by the paging.
+
+@vjeux
diff --git a/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts b/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts
index 04704d893b..02a12cf9bd 100644
--- a/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts
+++ b/packages/core/src/SnapPaging/__tests__/SnapPaging.interaction.browser.spec.ts
@@ -472,6 +472,34 @@ test.describe('with a finger and a mouse', () => {
expect(drift).toBe(0);
expect(await restingOffset(scroller)).toBeCloseTo(expected, 0);
});
+
+ test('a resize while the row settles back onto its stop hands the row back: a wheel then scrolls it', async ({
+ page,
+ }) => {
+ const {scroller} = await open(
+ page,
+ 'snap-paging-partial-last-page',
+ 'paging',
+ );
+ for (let i = 0; i < 7; i++) {
+ await swipe(page, scroller, {px: 80, ms: 80});
+ await settled(scroller);
+ }
+ // At the end, a flick settles back onto the same stop.
+ await swipe(page, scroller, {px: 80, ms: 80});
+ expect(await isTakenOver(scroller)).toBe(true);
+ await scroller.evaluate(el => {
+ el.style.width = `${el.clientWidth - 1}px`;
+ });
+ await settled(scroller);
+ // A row the paging still holds takes the wheel and stays put.
+ const at = await offset(scroller);
+ await scroller.hover();
+ await page.keyboard.down('Shift');
+ await page.mouse.wheel(0, -150);
+ await page.keyboard.up('Shift');
+ await expect.poll(async () => offset(scroller)).toBeLessThan(at - 1);
+ });
});
test('an edge press after a flick back near the end shows no space past the last item', async ({
diff --git a/packages/core/src/hooks/usePager.test.ts b/packages/core/src/hooks/usePager.test.ts
index cef22d471f..be75aae810 100644
--- a/packages/core/src/hooks/usePager.test.ts
+++ b/packages/core/src/hooks/usePager.test.ts
@@ -1048,6 +1048,63 @@ describe('createPager', () => {
}
});
+ it('a resize during a settle back to the page it left ends the settle with its callback', async () => {
+ let onResize: ResizeObserverCallback | null = null;
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ constructor(callback: ResizeObserverCallback) {
+ onResize = callback;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+ vi.resetModules();
+ const fresh = await import('./usePager');
+ const f = setup({defaultIndex: 0});
+ f.pager.dispose();
+ const calls: string[] = [];
+ const pager = fresh.createPager(
+ {
+ count: 5,
+ defaultIndex: 1,
+ onSettle: (i, previous) => calls.push(`settle:${i}:${previous}`),
+ },
+ {
+ host: f.host,
+ animator: f.animator,
+ requestFrame: callback => {
+ frameQueue.push(callback);
+ },
+ },
+ );
+ pager.attach(f.viewport, f.track);
+ try {
+ // A short, slow drag: the settle returns to page 1.
+ await drag(f, {from: 300, dx: -40, hold: 150});
+ await advance(16, f.clock);
+ expect(pager.isSettling).toBe(true);
+ Object.defineProperty(f.viewport, 'clientWidth', {
+ value: 300,
+ configurable: true,
+ });
+ expect(onResize).not.toBeNull();
+ onResize!(
+ [{target: f.viewport} as unknown as ResizeObserverEntry],
+ {} as ResizeObserver,
+ );
+ await advance(16, f.clock);
+ expect(pager.isSettling).toBe(false);
+ expect(f.x()).toBe(-300);
+ expect(calls).toEqual(['settle:1:1']);
+ } finally {
+ pager.dispose();
+ vi.unstubAllGlobals();
+ }
+ });
+
// The shared resize observer is one per module. So this case loads a fresh
// pager module after it installs its ResizeObserver.
it('a resize after a forward wrap keeps the wrapped page: no jump and no callback', async () => {
diff --git a/packages/core/src/hooks/usePager.ts b/packages/core/src/hooks/usePager.ts
index fbe6e912b2..d489235954 100644
--- a/packages/core/src/hooks/usePager.ts
+++ b/packages/core/src/hooks/usePager.ts
@@ -960,9 +960,11 @@ export function createPager(
// flight ends there), as a paging scroll view does on rotation. A finger
// that holds a caught track keeps it; its lift settles on the new offsets.
if (!isDragging && !caughtSettle) {
+ // A settle cut short still ends, even on the page it left.
+ const wasSettling = settleHandle != null;
stopSettle();
animator?.set({x: positionToX(offsetOf(target))});
- if (settled !== target) {
+ if (settled !== target || wasSettling) {
rest();
}
}