Skip to content

Commit

Permalink
feat(element): added support for using slots as swiper wrappers (#7624)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyoganesyan authored Jul 23, 2024
1 parent f4f7da0 commit e374e06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/events/onTouchStart.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getWindow, getDocument } from 'ssr-window';
import { now } from '../../shared/utils.mjs';
import { now, elementIsChildOf } from '../../shared/utils.mjs';

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

if (params.touchEventsTarget === 'wrapper') {
if (!swiper.wrapperEl.contains(targetEl)) return;
if (!elementIsChildOf(targetEl, swiper.wrapperEl)) return;
}
if ('which' in e && e.which === 3) return;
if ('button' in e && e.button > 0) return;
Expand Down
15 changes: 14 additions & 1 deletion src/shared/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,19 @@ function findElementsInElements(elements = [], selector = '') {
return found;
}
function elementChildren(element, selector = '') {
return [...element.children].filter((el) => el.matches(selector));
const children = [...element.children];
if(element instanceof HTMLSlotElement) {
children.push(...element.assignedElements())
}

if(!selector) {
return children;
}
return children.filter((el) => el.matches(selector));
}
function elementIsChildOf(el, parent) {
const children = elementChildren(parent);
return children.includes(el);
}
function showWarning(text) {
try {
Expand Down Expand Up @@ -343,6 +355,7 @@ export {
findElementsInElements,
createElement,
elementChildren,
elementIsChildOf,
elementOffset,
elementPrevAll,
elementNextAll,
Expand Down

0 comments on commit e374e06

Please sign in to comment.