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

chore(Carousel): pass active index onActiveIndexChange #16118

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/fluentui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Fix `Dropdown` to not break new lines for button trigger after listbox was introduced wrapping selected items @assuncaocharles ([#15898](https://github.com/microsoft/fluentui/pull/15898))
- Fix `Input` content overlaping with `Icon` @assuncaocharles ([#16083](https://github.com/microsoft/fluentui/pull/16083))
- Fix `variables` not being propagated in `Carousel` @assuncaocharles ([#16084](https://github.com/microsoft/fluentui/pull/16084))
- Fix `Carousel` `onActiveIndexChange` to contain `activeIndex` @assuncaocharles ([#16118](https://github.com/microsoft/fluentui/pull/16118))

### Features
- `Tree`: added `useTree` hook @yuanboxue-amber ([#15831](https://github.com/microsoft/fluentui/pull/15831))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const Carousel: ComponentWithAs<'div', CarouselProps> &

actions.setIndexes(nextActiveIndex, lastActiveIndex);

_.invoke(props, 'onActiveIndexChange', e, props);
_.invoke(props, 'onActiveIndexChange', e, { ...props, activeIndex: index });

if (focusItem) {
focusItemAtIndex(nextActiveIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ describe('Carousel', () => {
expect(pagination.getDOMNode().textContent).toBe(`2 of ${items.length}`);
});

it('should pass activeIndex onActiveIndexChange', () => {
const onActiveIndexChange = jest.fn();
const wrapper = renderCarousel({ onActiveIndexChange });
const paddleNext = getPaddleNextWrapper(wrapper);

paddleNext.simulate('click');

expect(onActiveIndexChange).toHaveBeenCalledWith(
expect.objectContaining({ type: 'click' }),
expect.objectContaining({ activeIndex: 1 }),
);
});

it('should decrese at paddle previous press', () => {
const wrapper = renderCarousel({ defaultActiveIndex: 3 });
const paddlePrevious = getPaddlePreviousWrapper(wrapper);
Expand Down