Skip to content

Commit

Permalink
Fix missing element if handler is a child of draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike committed Mar 21, 2020
1 parent ae5648c commit dc1305a
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/locations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,23 @@ export const inFrontOf: Location = ({source, direction}) => (target) => {

export const behind = inFrontOf

function dragIndexOf(el: HTMLElement) {
function dragIndexOf(handle: HTMLElement) {
const draggableEl = handle.closest(
`[${draggableAttribute}]`,
) as HTMLElement | null

if (!draggableEl) {
throw new Error(
`Could not find draggable element. Are you sure you provided a drag handler?`,
)
}

let index = null
const siblings = siblingsOf(el)

const siblings = siblingsOf(draggableEl)

for (const [i, v] of siblings.entries()) {
if (v === el) {
if (v === draggableEl) {
index = i
}
}
Expand Down

0 comments on commit dc1305a

Please # to comment.