From 1b6c2265e3b7803d70e8320e6ca8e6e0ba89fd4f Mon Sep 17 00:00:00 2001 From: Charles Assuncao Date: Wed, 2 Dec 2020 11:09:30 -0300 Subject: [PATCH 1/3] chore(Carousel): pass active index onActiveIndexChange --- .../react-northstar/src/components/Carousel/Carousel.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fluentui/react-northstar/src/components/Carousel/Carousel.tsx b/packages/fluentui/react-northstar/src/components/Carousel/Carousel.tsx index fc240be400618..a33542e79e638 100644 --- a/packages/fluentui/react-northstar/src/components/Carousel/Carousel.tsx +++ b/packages/fluentui/react-northstar/src/components/Carousel/Carousel.tsx @@ -261,7 +261,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); From 147b2acfb9ae977f18f9b5cc8f27b75150a18864 Mon Sep 17 00:00:00 2001 From: Charles Assuncao Date: Wed, 2 Dec 2020 11:11:58 -0300 Subject: [PATCH 2/3] chore(Carousel): add changelog --- packages/fluentui/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/fluentui/CHANGELOG.md b/packages/fluentui/CHANGELOG.md index 5924f67817637..3a067451b50bb 100644 --- a/packages/fluentui/CHANGELOG.md +++ b/packages/fluentui/CHANGELOG.md @@ -57,6 +57,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Fix shorthand `id` prop not being passed to control in `FormField` component @assuncaocharles ([#16003](https://github.com/microsoft/fluentui/pull/16003)) - Fix outdated `onChange` call in `RadioGroupItem` @assuncaocharles ([#15997](https://github.com/microsoft/fluentui/pull/15997)) - 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 `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)) From 5d1b35e7f9f546a75603ab9680e3cb2b51aec611 Mon Sep 17 00:00:00 2001 From: Charles Assuncao Date: Wed, 2 Dec 2020 11:28:30 -0300 Subject: [PATCH 3/3] chore(Carousel): add test --- .../specs/components/Carousel/Carousel-test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/fluentui/react-northstar/test/specs/components/Carousel/Carousel-test.tsx b/packages/fluentui/react-northstar/test/specs/components/Carousel/Carousel-test.tsx index 4f84f1015b233..448193f8a8281 100644 --- a/packages/fluentui/react-northstar/test/specs/components/Carousel/Carousel-test.tsx +++ b/packages/fluentui/react-northstar/test/specs/components/Carousel/Carousel-test.tsx @@ -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);