Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7623: Added support for using slots as swiper wrappers #7624

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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