Skip to content

Commit 2bbb5be

Browse files
committed
Fix selection in deeper children
1 parent 1156fe8 commit 2bbb5be

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/eventHandlers/mousedown.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@ export const selectNames = [
1212
'user-select'
1313
];
1414

15+
function findParent(el: Element, sel: string): Element {
16+
let result = el;
17+
while (!result.matches(sel)) {
18+
if (result.matches('html')) {
19+
throw new Error('no parent element found');
20+
}
21+
result = result.parentElement;
22+
}
23+
return result;
24+
}
25+
1526
export function mousedownHandler(
1627
node: VNode,
1728
ev: MouseEvent,
1829
opts: SortableOptions
1930
): [VNode, undefined] {
20-
const item: Element = ev.currentTarget as Element;
31+
const item: Element = findParent(ev.target as Element, opts.itemSelector);
2132
const indexClicked = Array.prototype.slice
2233
.call(item.parentElement.children)
2334
.indexOf(item);

0 commit comments

Comments
 (0)