From 908becc6ffbf5b5a050e2fde522867289073cf4a Mon Sep 17 00:00:00 2001 From: Vladimir Kharlampidi Date: Thu, 21 Sep 2023 13:00:46 +0300 Subject: [PATCH] fix(core): remove grid class on rows change fixes #7053 --- src/modules/grid/grid.mjs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/modules/grid/grid.mjs b/src/modules/grid/grid.mjs index ba3bfcbd1..8077cdf71 100644 --- a/src/modules/grid/grid.mjs +++ b/src/modules/grid/grid.mjs @@ -1,4 +1,4 @@ -export default function Grid({ swiper, extendParams }) { +export default function Grid({ swiper, extendParams, on }) { extendParams({ grid: { rows: 1, @@ -9,6 +9,7 @@ export default function Grid({ swiper, extendParams }) { let slidesNumberEvenToRows; let slidesPerRow; let numFullColumns; + let wasMultiRow; const getSpaceBetween = () => { let spaceBetween = swiper.params.spaceBetween; @@ -96,6 +97,33 @@ export default function Grid({ swiper, extendParams }) { snapGrid.push(...newSlidesGrid); } }; + const onInit = () => { + wasMultiRow = swiper.params.grid && swiper.params.grid.rows > 1; + }; + + const onUpdate = () => { + const { params, el } = swiper; + const isMultiRow = params.grid && params.grid.rows > 1; + + if (wasMultiRow && !isMultiRow) { + el.classList.remove( + `${params.containerModifierClass}grid`, + `${params.containerModifierClass}grid-column`, + ); + numFullColumns = 1; + swiper.emitContainerClasses(); + } else if (!wasMultiRow && isMultiRow) { + el.classList.add(`${params.containerModifierClass}grid`); + if (params.grid.fill === 'column') { + el.classList.add(`${params.containerModifierClass}grid-column`); + } + swiper.emitContainerClasses(); + } + wasMultiRow = isMultiRow; + }; + + on('init', onInit); + on('update', onUpdate); swiper.grid = { initSlides,