diff --git a/src/components/Carousel/Carousel.svelte b/src/components/Carousel/Carousel.svelte index ed1d46d..7463cbb 100644 --- a/src/components/Carousel/Carousel.svelte +++ b/src/components/Carousel/Carousel.svelte @@ -53,7 +53,7 @@ /** * Infinite looping */ - export let infinite + export let infinite = false $: { data.infinite = infinite } diff --git a/src/components/Carousel/createCarousel.js b/src/components/Carousel/createCarousel.js index 18c6fb0..29276db 100644 --- a/src/components/Carousel/createCarousel.js +++ b/src/components/Carousel/createCarousel.js @@ -113,6 +113,7 @@ function createCarousel(onChange) { infinite: data.infinite, particlesCountWithoutClones: data.particlesCountWithoutClones, particlesToScroll: data.particlesToScroll, + particlesToShow: data.particlesToShow, }) }, setParticlesToShow({ data }) { diff --git a/src/utils/page.js b/src/utils/page.js index e4d7679..69a919b 100644 --- a/src/utils/page.js +++ b/src/utils/page.js @@ -60,14 +60,21 @@ export function _getPagesCountByParticlesCountInfinite({ export function _getPagesCountByParticlesCountLimited({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, }) { - return Math.round(particlesCountWithoutClones / particlesToScroll) + const partialPageSize = getPartialPageSize({ + particlesCountWithoutClones, + particlesToScroll, + particlesToShow, + }) + return Math.ceil(particlesCountWithoutClones / particlesToScroll) - partialPageSize } export function getPagesCountByParticlesCount({ infinite, particlesCountWithoutClones, particlesToScroll, + particlesToShow, }) { return infinite ? _getPagesCountByParticlesCountInfinite({ @@ -77,6 +84,7 @@ export function getPagesCountByParticlesCount({ : _getPagesCountByParticlesCountLimited({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, }) } diff --git a/src/utils/page.test.js b/src/utils/page.test.js index 7a9cbb0..ab47602 100644 --- a/src/utils/page.test.js +++ b/src/utils/page.test.js @@ -435,17 +435,42 @@ describe('_getPagesCountByParticlesCountLimited', () => { const testCases = [{ particlesCountWithoutClones: 5, particlesToScroll: 2, - expected: 3, + particlesToShow: 3, + expected: 2, }] testCases.forEach(({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, expected, }) => { expect(_getPagesCountByParticlesCountLimited({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, + })).toBe(expected) + }) + }) + + it('returns result as expected if particlesCountWithoutClones: 9; particlesToScroll: 2 (particlesToShow: 3)', () => { + const testCases = [{ + particlesCountWithoutClones: 9, + particlesToScroll: 2, + particlesToShow: 3, + expected: 4, + }] + + testCases.forEach(({ + particlesCountWithoutClones, + particlesToScroll, + particlesToShow, + expected, + }) => { + expect(_getPagesCountByParticlesCountLimited({ + particlesCountWithoutClones, + particlesToScroll, + particlesToShow, })).toBe(expected) }) }) @@ -454,17 +479,20 @@ describe('_getPagesCountByParticlesCountLimited', () => { const testCases = [{ particlesCountWithoutClones: 6, particlesToScroll: 2, + particlesToShow: 2, expected: 3, }] testCases.forEach(({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, expected, }) => { expect(_getPagesCountByParticlesCountLimited({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, })).toBe(expected) }) }) @@ -473,17 +501,20 @@ describe('_getPagesCountByParticlesCountLimited', () => { const testCases = [{ particlesCountWithoutClones: 5, particlesToScroll: 3, + particlesToShow: 2, expected: 2, }] testCases.forEach(({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, expected, }) => { expect(_getPagesCountByParticlesCountLimited({ particlesCountWithoutClones, particlesToScroll, + particlesToShow, })).toBe(expected) }) })