You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I found this bug while using your library. I am willing to create a PR to fix this if you'd like.
Steps to reproduce
Use display: contents on an element
Make a Droppable with it
It doesn't work (the Droppable only uses the bounding box of the container to calculate the droppable area, which is always [0,0,0,0] on elements with display: contents)
Expected behavior
If the bounding box is [0,0,0,0], the Droppable should use the union of the bounding boxes of any not-absolutely-positioned children as the droppable area.
Code
This code doesn't work
importagnosticDraggablefrom"https://cdn.skypack.dev/[email protected]";const{ Draggable, Droppable }=agnosticDraggableconstapp=document.createElement("div")constdata=[{name: "foo",number: 100,date: newDate(Date.now()-2*60*1000).toLocaleString()},{name: "bar",number: 200,date: newDate(Date.now()-60*1000).toLocaleString()},{name: "baz",number: 300,date: newDate(Date.now()).toLocaleString()}]consttable=document.createElement("table")table.style.width="calc(100% - 40px)"table.style.margin="20px"table.style.display="grid"table.style.gridTemplateColumns="auto auto auto"constthead=document.createElement("thead")thead.style.display="contents"consttbody=document.createElement("tbody")tbody.style.display="contents"consttr=document.createElement("tr")tr.style.display="contents"for(constcolofObject.keys(data[0])){constth=document.createElement("th")th.style.background="rgba(127, 127, 127, .1)"th.style.padding="8px"th.style.border="solid rgb(127,127,127)"th.style.borderWidth="1px 0"th.textContent=coltr.appendChild(th)}thead.appendChild(tr)for(constrowofdata){consttr=document.createElement("tr")tr.style.display="contents"constcells=Object.values(row).map((cell)=>{consttd=document.createElement("td")td.style.padding="8px"td.style.border="solid rgb(127,127,127)"td.style.borderWidth="1px 0"td.textContent=celltr.appendChild(td)})tbody.appendChild(tr)newDroppable(tr,{tolerance: "pointer",},{"droppable:over": ()=>{tr.style.background="blue"},"droppable:out": ()=>{tr.style.background=""},"droppable:drop": ()=>{tr.style.background=""consttd=tr.querySelector("td:nth-child(2)")td.textContent=parseInt(td.textContent)+1}})}table.appendChild(thead)table.appendChild(tbody)app.appendChild(table)constaddDiv=document.createElement("div")addDiv.style.display="inline-block"addDiv.style.margin="20px"addDiv.style.padding="8px"addDiv.style.background="rgb(127,127,127)"addDiv.textContent="Drop me on a row to add 1"app.appendChild(addDiv)document.body.appendChild(app)letlistener=(e)=>{e.preventDefault()}newDraggable(addDiv,{revert: true,},{"drag:start": ()=>{document.body.addEventListener("selectstart",listener)},"drag:stop": ()=>{document.body.removeEventListener("selectstart",listener)}})
This code works
importagnosticDraggablefrom"https://cdn.skypack.dev/[email protected]";const{ Draggable, Droppable }=agnosticDraggableconstapp=document.createElement("div")constdata=[{name: "foo",number: 100,date: newDate(Date.now()-2*60*1000).toLocaleString()},{name: "bar",number: 200,date: newDate(Date.now()-60*1000).toLocaleString()},{name: "baz",number: 300,date: newDate(Date.now()).toLocaleString()}]consttable=document.createElement("table")table.style.width="calc(100% - 40px)"table.style.margin="20px"constthead=document.createElement("thead")consttbody=document.createElement("tbody")consttr=document.createElement("tr")for(constcolofObject.keys(data[0])){constth=document.createElement("th")th.style.background="rgba(127, 127, 127, .1)"th.style.padding="8px"th.style.border="solid rgb(127,127,127)"th.style.borderWidth="1px 0"th.textContent=coltr.appendChild(th)}thead.appendChild(tr)for(constrowofdata){consttr=document.createElement("tr")constcells=Object.values(row).map((cell)=>{consttd=document.createElement("td")td.style.padding="8px"td.style.border="solid rgb(127,127,127)"td.style.borderWidth="1px 0"td.textContent=celltr.appendChild(td)})tbody.appendChild(tr)newDroppable(tr,{tolerance: "pointer",},{"droppable:over": ()=>{tr.style.background="blue"},"droppable:out": ()=>{tr.style.background=""},"droppable:drop": ()=>{tr.style.background=""consttd=tr.querySelector("td:nth-child(2)")td.textContent=parseInt(td.textContent)+1}})}table.appendChild(thead)table.appendChild(tbody)app.appendChild(table)constaddDiv=document.createElement("div")addDiv.style.display="inline-block"addDiv.style.margin="20px"addDiv.style.padding="8px"addDiv.style.background="rgb(127,127,127)"addDiv.textContent="Drop me on a row to add 1"app.appendChild(addDiv)document.body.appendChild(app)letlistener=(e)=>{e.preventDefault()}newDraggable(addDiv,{revert: true,},{"drag:start": ()=>{document.body.addEventListener("selectstart",listener)},"drag:stop": ()=>{document.body.removeEventListener("selectstart",listener)}})
Suggested solution
If the Droppable element has a bounding box of [0,0,0,0], search deeply for any children (excluding position: absolute or position: fixed) that have a not-zero bounding box
Use those bounding boxes to test whether a Draggable is over the Droppable
The text was updated successfully, but these errors were encountered:
Hi, I found this bug while using your library. I am willing to create a PR to fix this if you'd like.
Steps to reproduce
display: contents
on an elementdisplay: contents
)Expected behavior
If the bounding box is [0,0,0,0], the Droppable should use the union of the bounding boxes of any not-absolutely-positioned children as the droppable area.
Code
This code doesn't work
This code works
Suggested solution
position: absolute
orposition: fixed
) that have a not-zero bounding boxThe text was updated successfully, but these errors were encountered: