mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 13:09:40 +08:00
adjust Carousel children change goto Logic (#16756)
This commit is contained in:
parent
7884ea72f0
commit
5ab2783ff0
@ -106,12 +106,28 @@ describe('Carousel', () => {
|
|||||||
warnSpy.mockRestore();
|
warnSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should active when children change', () => {
|
describe('should active when children change', () => {
|
||||||
const wrapper = mount(<Carousel />);
|
it('should active', () => {
|
||||||
wrapper.setProps({
|
const wrapper = mount(<Carousel />);
|
||||||
children: <div />,
|
wrapper.setProps({
|
||||||
|
children: <div />,
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
expect(wrapper.find('.slick-active').length).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should keep initialSlide', () => {
|
||||||
|
const wrapper = mount(<Carousel initialSlide={1} />);
|
||||||
|
wrapper.setProps({
|
||||||
|
children: [<div key="1" />, <div key="2" />, <div key="3" />],
|
||||||
|
});
|
||||||
|
wrapper.update();
|
||||||
|
expect(
|
||||||
|
wrapper
|
||||||
|
.find('.slick-dots li')
|
||||||
|
.at(1)
|
||||||
|
.hasClass('slick-active'),
|
||||||
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
wrapper.update();
|
|
||||||
expect(wrapper.find('.slick-active').length).toBeTruthy();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,7 @@ export default class Carousel extends React.Component<CarouselProps, {}> {
|
|||||||
|
|
||||||
componentDidUpdate(prevProps: CarouselProps) {
|
componentDidUpdate(prevProps: CarouselProps) {
|
||||||
if (React.Children.count(this.props.children) !== React.Children.count(prevProps.children)) {
|
if (React.Children.count(this.props.children) !== React.Children.count(prevProps.children)) {
|
||||||
this.goTo(0, false);
|
this.goTo(this.props.initialSlide || 0, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user