Skip to content

Commit

Permalink
fix: drag shadow on Safari (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
Accir authored Dec 26, 2023
1 parent 2845ac8 commit e4bc34c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-planets-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@craftjs/core': patch
---

fix Safari drag shadow
8 changes: 5 additions & 3 deletions packages/core/src/events/createShadow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: this approach does not work with Safari
// Works partially with Linux (except on Chrome)
// We'll need an alternate way to create drag shadows
export const createShadow = (
Expand All @@ -10,12 +9,13 @@ export const createShadow = (
const { width, height } = shadowsToCreate[0].getBoundingClientRect();
const shadow = shadowsToCreate[0].cloneNode(true) as HTMLElement;

shadow.style.position = `fixed`;
shadow.style.position = `absolute`;
shadow.style.left = `-100%`;
shadow.style.top = `-100%`;
shadow.style.width = `${width}px`;
shadow.style.height = `${height}px`;
shadow.style.pointerEvents = 'none';
shadow.classList.add('drag-shadow');

document.body.appendChild(shadow);
e.dataTransfer.setDragImage(shadow, 0, 0);
Expand All @@ -28,12 +28,13 @@ export const createShadow = (
* That container will be used as the drag shadow for the current drag event
*/
const container = document.createElement('div');
container.style.position = 'fixed';
container.style.position = 'absolute';
container.style.left = '-100%';
container.style.top = `-100%`;
container.style.width = '100%';
container.style.height = '100%';
container.style.pointerEvents = 'none';
container.classList.add('drag-shadow-container');

shadowsToCreate.forEach((dom) => {
const { width, height, top, left } = dom.getBoundingClientRect();
Expand All @@ -44,6 +45,7 @@ export const createShadow = (
shadow.style.top = `${top}px`;
shadow.style.width = `${width}px`;
shadow.style.height = `${height}px`;
shadow.classList.add('drag-shadow');

container.appendChild(shadow);
});
Expand Down

0 comments on commit e4bc34c

Please sign in to comment.