Skip to content

Commit

Permalink
fix(core): remove grid class on rows change
Browse files Browse the repository at this point in the history
fixes #7053
  • Loading branch information
nolimits4web committed Sep 21, 2023
1 parent 5ca46b6 commit 908becc
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/modules/grid/grid.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function Grid({ swiper, extendParams }) {
export default function Grid({ swiper, extendParams, on }) {
extendParams({
grid: {
rows: 1,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 908becc

Please sign in to comment.