Skip to content
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

Conversation

Mitch-At-Work
Copy link
Contributor

@Mitch-At-Work Mitch-At-Work commented Jul 16, 2024

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.

@fabricteam
Copy link
Collaborator

fabricteam commented Jul 16, 2024

📊 Bundle size report

✅ No changes found

@Mitch-At-Work Mitch-At-Work force-pushed the user/mifraser/enable-embla-grouping branch from 1b70a8a to ed96b90 Compare July 18, 2024 17:47
@Mitch-At-Work Mitch-At-Work marked this pull request as ready for review July 18, 2024 17:58
@Mitch-At-Work Mitch-At-Work requested review from a team as code owners July 18, 2024 17:58
@Mitch-At-Work Mitch-At-Work force-pushed the user/mifraser/enable-embla-grouping branch from ed96b90 to c302937 Compare July 23, 2024 17:17

/**
* Controls whether the scrollView will trim whitespace in order to position trailing items via alignment
* Default: false.
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@default: 1?

Copy link
Contributor

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?

Comment on lines +15 to +35
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>
);
}
Copy link
Member

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

Comment on lines +188 to +190
setStartIndex(index);
// Sets the nav items
setValue(values[cardIndex]);
Copy link
Member

@layershifter layershifter Jul 23, 2024

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);
Copy link
Member

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?

@Mitch-At-Work Mitch-At-Work marked this pull request as draft July 23, 2024 18:15
@Mitch-At-Work
Copy link
Contributor Author

Closed in favor of: #32113

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.

4 participants