Skip to content

Commit 45f8d4a

Browse files
committed
fix(element): remove/re-add navigation, pagination, scrollbar elements based on prop value
fixes #6672
1 parent 7f3fa96 commit 45f8d4a

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/components-shared/update-swiper.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function updateSwiper({
2222
let loopNeedDestroy;
2323
let loopNeedEnable;
2424
let loopNeedReloop;
25-
2625
if (
2726
changedParams.includes('thumbs') &&
2827
passedParams.thumbs &&
@@ -109,6 +108,13 @@ function updateSwiper({
109108
updateParams.forEach((key) => {
110109
if (isObject(currentParams[key]) && isObject(passedParams[key])) {
111110
extend(currentParams[key], passedParams[key]);
111+
if (
112+
(key === 'navigation' || key === 'pagination' || key === 'scrollbar') &&
113+
'enabled' in passedParams[key] &&
114+
!passedParams[key].enabled
115+
) {
116+
destroyModule(key);
117+
}
112118
} else {
113119
const newValue = passedParams[key];
114120
if (

src/element/get-params.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const modulesParamsList = [
3737
'zoom',
3838
];
3939

40-
function getParams(element) {
40+
function getParams(element, propName, propValue) {
4141
const params = {};
4242
const passedParams = {};
4343
extend(params, defaults);
@@ -55,14 +55,18 @@ function getParams(element) {
5555
});
5656

5757
// Attributes
58-
[...element.attributes].forEach((attr) => {
58+
const attrsList = [...element.attributes];
59+
if (typeof propName === 'string' && typeof propValue !== 'undefined') {
60+
attrsList.push({ name: propName, value: propValue });
61+
}
62+
attrsList.forEach((attr) => {
5963
const moduleParam = modulesParamsList.filter(
6064
(mParam) => attr.name.indexOf(`${mParam}-`) === 0,
6165
)[0];
6266
if (moduleParam) {
6367
const parentObjName = attrToProp(moduleParam);
6468
const subObjName = attrToProp(attr.name.split(`${moduleParam}-`)[1]);
65-
if (!passedParams[parentObjName]) passedParams[parentObjName] = {};
69+
if (typeof passedParams[parentObjName] === 'undefined') passedParams[parentObjName] = {};
6670
if (passedParams[parentObjName] === true) {
6771
passedParams[parentObjName] = { enabled: true };
6872
}
@@ -111,7 +115,6 @@ function getParams(element) {
111115
} else if (params.pagination === false) {
112116
delete params.pagination;
113117
}
114-
115118
return { params, passedParams };
116119
}
117120

src/element/swiper-element.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class SwiperContainer extends ClassToExtend {
165165
this.initialized = false;
166166
}
167167

168-
updateSwiperOnPropChange(propName) {
169-
const { params: swiperParams, passedParams } = getParams(this);
168+
updateSwiperOnPropChange(propName, propValue) {
169+
const { params: swiperParams, passedParams } = getParams(this, propName, propValue);
170170
this.passedParams = passedParams;
171171
this.swiperParams = swiperParams;
172172

@@ -195,6 +195,9 @@ class SwiperContainer extends ClassToExtend {
195195

196196
attributeChangedCallback(attr, prevValue, newValue) {
197197
if (!this.initialized) return;
198+
if (prevValue === 'true' && newValue === null) {
199+
newValue = false;
200+
}
198201
this.updateSwiperOnPropChange(attr, newValue);
199202
}
200203

@@ -223,7 +226,7 @@ paramsList.forEach((paramName) => {
223226
if (!this.passedParams) this.passedParams = {};
224227
this.passedParams[paramName] = value;
225228
if (!this.initialized) return;
226-
this.updateSwiperOnPropChange(paramName, value);
229+
this.updateSwiperOnPropChange(paramName);
227230
},
228231
});
229232
});

0 commit comments

Comments
 (0)