Skip to content

fix(core): keep the active slide when the window resizes in large steps - #15

Merged
mitchellslager merged 1 commit into
mainfrom
fix/resize-alignment
Nov 9, 2026
Merged

mitchellslager merged 1 commit into
mainfrom
fix/resize-alignment

Conversation

@mitchellslager

Copy link
Copy Markdown
Owner

Resizing the window in a large step, such as from a phone width to a desktop width, could leave the carousel on another slide or between two. Browsers scroll on their own when the viewport resizes: they clamp the offset when it shrinks, and Firefox later scrolls back, smoothly, to the slide it was clamped to. The earlier resize fix only handled small steps.

Changes

  • Until the resize observer has seen the new width, the tracker ignores the scroll position, which would mix the old offset with the new slide widths.
  • After a resize the active slide is put back in the centre and pinned there: scrolls the browser starts are undone, until resizing has been quiet for 250 ms or the user interacts with the carousel.
  • New tests resize the test window between phone and desktop widths, resize every frame, and scroll straight after a resize. The window test failed on the old code in WebKit and Firefox.
  • DESIGN.md is updated, and a patch changeset is included.

Browsers clamp the scroll offset when the viewport shrinks, and Firefox later scrolls back to the slide it was clamped to. The tracker now ignores the scroll position until the resize observer has seen the new width, then pins the active slide in the centre, undoing scrolls the browser starts, until the resize is quiet or the user interacts.
@mitchellslager
mitchellslager merged commit a2757a0 into main Nov 9, 2026
2 checks passed
@mitchellslager
mitchellslager deleted the fix/resize-alignment branch November 9, 2026 11:54
@github-actions github-actions Bot mentioned this pull request Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant