Skip to content

Commit e374e06

Browse files
feat(element): added support for using slots as swiper wrappers (#7624)
1 parent f4f7da0 commit e374e06

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/core/events/onTouchStart.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getWindow, getDocument } from 'ssr-window';
2-
import { now } from '../../shared/utils.mjs';
2+
import { now, elementIsChildOf } from '../../shared/utils.mjs';
33

44
// Modified from https://stackoverflow.com/questions/54520554/custom-element-getrootnode-closest-function-crossing-multiple-parent-shadowd
55
function closestElement(selector, base = this) {
@@ -67,7 +67,7 @@ export default function onTouchStart(event) {
6767
let targetEl = e.target;
6868

6969
if (params.touchEventsTarget === 'wrapper') {
70-
if (!swiper.wrapperEl.contains(targetEl)) return;
70+
if (!elementIsChildOf(targetEl, swiper.wrapperEl)) return;
7171
}
7272
if ('which' in e && e.which === 3) return;
7373
if ('button' in e && e.button > 0) return;

src/shared/utils.mjs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,19 @@ function findElementsInElements(elements = [], selector = '') {
203203
return found;
204204
}
205205
function elementChildren(element, selector = '') {
206-
return [...element.children].filter((el) => el.matches(selector));
206+
const children = [...element.children];
207+
if(element instanceof HTMLSlotElement) {
208+
children.push(...element.assignedElements())
209+
}
210+
211+
if(!selector) {
212+
return children;
213+
}
214+
return children.filter((el) => el.matches(selector));
215+
}
216+
function elementIsChildOf(el, parent) {
217+
const children = elementChildren(parent);
218+
return children.includes(el);
207219
}
208220
function showWarning(text) {
209221
try {
@@ -343,6 +355,7 @@ export {
343355
findElementsInElements,
344356
createElement,
345357
elementChildren,
358+
elementIsChildOf,
346359
elementOffset,
347360
elementPrevAll,
348361
elementNextAll,

0 commit comments

Comments
 (0)