Skip to content

Commit

Permalink
fix: add optional swiperElementNodeName param to allow more flexible …
Browse files Browse the repository at this point in the history
…web component usage (#7284)
  • Loading branch information
sghoweri authored Feb 5, 2024
1 parent 76355b8 commit 178511f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/components-shared/params-list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const paramsList = [
'init',
'_direction',
'oneWayMovement',
'swiperElementNodeName',
'touchEventsTarget',
'initialSlide',
'_speed',
Expand Down
2 changes: 1 addition & 1 deletion src/core/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ class Swiper {
}

el.swiper = swiper;
if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === 'SWIPER-CONTAINER') {
if (el.parentNode && el.parentNode.host && el.parentNode.host.nodeName === swiper.params.swiperElementNodeName.toUpperCase()) {
swiper.isElement = true;
}

Expand Down
1 change: 1 addition & 0 deletions src/core/defaults.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export default {
init: true,
direction: 'horizontal',
oneWayMovement: false,
swiperElementNodeName: 'SWIPER-CONTAINER',
touchEventsTarget: 'wrapper',
initialSlide: 0,
speed: 300,
Expand Down
4 changes: 4 additions & 0 deletions src/swiper-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ declare const Swiper: DefineComponent<
type: PropType<SwiperOptions['oneWayMovement']>;
default: SwiperOptions['oneWayMovement'];
};
swiperElementNodeName: {
type: PropType<SwiperOptions['swiperElementNodeName']>;
default: SwiperOptions['swiperElementNodeName'];
};
touchEventsTarget: {
type: PropType<SwiperOptions['touchEventsTarget']>;
default: undefined;
Expand Down
7 changes: 7 additions & 0 deletions src/types/swiper-options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ export interface SwiperOptions {

oneWayMovement?: boolean;

/**
* The name of the swiper element node name; used for detecting web component rendering
*
* @default 'SWIPER-CONTAINER'
*/
swiperElementNodeName?: string;

/**
* Duration of transition between slides (in ms)
*
Expand Down
1 change: 1 addition & 0 deletions src/vue/swiper.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Swiper = {
init: { type: Boolean, default: undefined },
direction: { type: String, default: undefined },
oneWayMovement: { type: Boolean, default: undefined },
swiperElementNodeName: { type: String, default: 'SWIPER-CONTAINER' },
touchEventsTarget: { type: String, default: undefined },
initialSlide: { type: Number, default: undefined },
speed: { type: Number, default: undefined },
Expand Down

0 comments on commit 178511f

Please sign in to comment.