Skip to content

Commit

Permalink
Merge pull request #113 from ant-design/fix/duplicated-items
Browse files Browse the repository at this point in the history
fix: duplicated items when children count is 1
  • Loading branch information
afc163 committed Apr 1, 2024
2 parents 117e432 + dedf10f commit b360e92
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 16 additions & 1 deletion __tests__/regression/fix-1813.test.js
Expand Up @@ -12,7 +12,6 @@ import {
getButtons,
getButtonsLength,
getClonesCount,
getCurrentSlide,
getSlidesCount
} from "../../test-utils";
import { GenericSliderComponent } from "../TestComponents";
Expand All @@ -28,13 +27,29 @@ function MultipleItems() {
return <GenericSliderComponent slidesCount={9} settings={settings} />;
}

function SingleItem() {
const settings = {
dots: true,
infinite: true,
speed: 500,
slidesToShow: 1
};
return <GenericSliderComponent slidesCount={1} settings={settings} />;
}

describe("Multiple Items with slidesToShow = slides count in infinite mode", function () {
it("should have 9 actual slides and (9(pre) + 9(post)) clone slides", function () {
//Todo: Need to fix extra clones
const { container } = render(<MultipleItems />);
expect(getSlidesCount(container)).toEqual(27);
expect(getClonesCount(container)).toEqual(18);
});
// https://github.com/akiran/react-slick/issues/2359
it("should not have cloned slide", function () {
const { container } = render(<SingleItem />);
expect(getSlidesCount(container)).toEqual(1);
expect(getClonesCount(container)).toEqual(0);
});
it("should have 9 active slides", function () {
const { container } = render(<MultipleItems />);
expect(getActiveSlidesCount(container)).toEqual(9);
Expand Down
7 changes: 6 additions & 1 deletion src/track.js
Expand Up @@ -136,7 +136,12 @@ const renderSlides = (spec) => {
);

// if slide needs to be precloned or postcloned
if (spec.infinite && spec.fade === false && !spec.unslick) {
if (
spec.infinite &&
childrenCount > 1 &&
spec.fade === false &&
!spec.unslick
) {
let preCloneNo = childrenCount - index;
if (preCloneNo <= getPreClones(spec)) {
key = -preCloneNo;
Expand Down

0 comments on commit b360e92

Please sign in to comment.