-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Carousel: Groups #32024
Carousel: Groups #32024
Conversation
📊 Bundle size report✅ No changes found |
1b70a8a
to
ed96b90
Compare
ed96b90
to
c302937
Compare
|
||
/** | ||
* Controls whether the scrollView will trim whitespace in order to position trailing items via alignment | ||
* Default: false. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: use the jsdoc notation
/** | ||
* Group size enables pagination of multiple cards as a single slide | ||
*/ | ||
groupSize?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@default: 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to try and handle cases where a user (likely accidentally) inputs non positive or non-whole numbers?
if (groupSize) { | ||
const groupValues: string[][] = []; | ||
let groupIndex = -1; | ||
values.forEach((value, index) => { | ||
if (index % groupSize === 0) { | ||
groupIndex++; | ||
groupValues[groupIndex] = []; | ||
} | ||
groupValues[groupIndex].push(value); | ||
}); | ||
|
||
return ( | ||
<state.root> | ||
{groupValues.map(value => ( | ||
<CarouselNavContextProvider value={value} key={value.join('-')}> | ||
{renderNavButton(value)} | ||
</CarouselNavContextProvider> | ||
))} | ||
</state.root> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be no computations in render functions
setStartIndex(index); | ||
// Sets the nav items | ||
setValue(values[cardIndex]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to cause a re-render after initial mount :(
@@ -165,10 +175,21 @@ export function useCarousel_unstable(props: CarouselProps, ref: React.Ref<HTMLDi | |||
}); | |||
|
|||
useIsomorphicLayoutEffect(() => { | |||
if (isFirstMount && value) { | |||
scrollToValue(value, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't scroll anymore?
Closed in favor of: #32113 |
Previous Behavior
Users could place multiple items in the carousel view, with one navigation item per item.
Users could have multiple items within a single CarouselCard, but would require custom logic that would separate the visual cards from the actual carousel slides - this will cause future issues with our focus and accessibility implementations, so we need a way to group internally via carousel hooks.
New Behavior
GroupSize variable enables users to define groups of elements as a single navigation point, without having to build custom logic to place items in a single card.
Carousel nav buttons will now take a list of items, and will use the first index as the navigation points.
We ensure that the first item is the active value so that movement for next/previous is consistent every time.