Skip to content

fix(card-carousel): use CSS scroll-behavior instead of JS behavior:'s…#42

Open
krishpranav wants to merge 1 commit into
rust-ui:mainfrom
krishpranav:fix/card-carousel-snap-scroll
Open

fix(card-carousel): use CSS scroll-behavior instead of JS behavior:'s…#42
krishpranav wants to merge 1 commit into
rust-ui:mainfrom
krishpranav:fix/card-carousel-snap-scroll

Conversation

@krishpranav
Copy link
Copy Markdown
Contributor

@krishpranav krishpranav commented May 19, 2026

What broke
After PR #39, the carousel nav buttons stopped working on WebKit based browsers.

Fix
The JS scrollBy() call with explicit behavior: 'smooth' was conflicting with scroll-snap-type: mandatory on WebKit.

Switched to scroll_by_with_x_and_y() (default auto behavior) so it respects the CSS scroll-behavior: smooth. Also cleaned up unused web-sys features.

Tested with cargo build + cargo clippy. Fixes the regression from #39.

…mooth'

The click handler was calling scrollBy() with an explicit ScrollToOptions
{ behavior: 'smooth' }, which overrides the element's CSS scroll-behavior
property. On WebKit (Safari / iOS), this combination with scroll-snap-type:
mandatory prevents the snap point from being committed — the carousel either
fails to move or lands between slides.

The fix drops ScrollBehavior::Smooth and ScrollToOptions entirely, switching
to scroll_by_with_x_and_y(delta, 0.0). This matches the original JS
implementation which relied on the track's CSS scroll-smooth class for
animation and let the browser's native snap logic run uninterrupted.

Removed the now-unused ScrollBehavior and ScrollToOptions web-sys features
from the workspace Cargo.toml.
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