Skip to content

Conversation

@oscarcarlstrom
Copy link
Contributor

@oscarcarlstrom oscarcarlstrom commented Nov 3, 2025

Introduce controlled selection for the <Carousel> component, allowing external management of the selected index.

This way it is possible to use for example query params to decide where the Carousel should start. Or auto-scroll with setTimeout:

Screen.Recording.2025-11-13.at.12.08.09.mov

My initial thought was to consolidate the onSelectedIndexChange and the onChange callbacks. The onChange callback was initially added to support tracking, and this is used by some consumers already. I haven't found any easy way to make the onSelectedIndexChange callback flexible enough to support both CarouselItem | number (for tracking you probably want CarouselItem, but for regular controlled state management the index (number) is much easier. The callback also needs to be of type SetStateAction, since the next/prev "buttons" bases the new state set on the current state. A simple approach would be to just scrap onChange altogether, but then that would require the consumer to put the component in a controlled state just to be able to track changes. Which also feels a bit much to ask. So I suggest we initially just keep the onChange prop for tracking purposes, and separate that from controlled state management.

@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

🦋 Changeset detected

Latest commit: 4b048bd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@obosbbl/grunnmuren-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@oscarcarlstrom oscarcarlstrom marked this pull request as ready for review December 17, 2025 09:30
@oscarcarlstrom oscarcarlstrom requested a review from a team as a code owner December 17, 2025 09:30
@alexanbj alexanbj closed this Jan 6, 2026
@alexanbj alexanbj deleted the controlled-carousel branch January 6, 2026 10:36
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.

3 participants