Skip to content

Commit

Permalink
fix: fix offsetParent with willChange #711
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Aug 3, 2022
1 parent 4f04200 commit cd1de86
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/react-moveable/src/react-moveable/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,15 @@ export function getOffsetInfo(
const style = getComputedStyle(target);
const tagName = target.tagName.toLowerCase();
const transform = getElementTransform(target as SVGElement, style);
const willChange = style.willChange;
position = style.position!;

if (tagName === "svg" || position !== "static" || (transform && transform !== "none")) {
if (
tagName === "svg"
|| position !== "static"
|| (transform && transform !== "none")
|| willChange === "transform"
) {
break;
}
const parentNode = target.parentNode;
Expand Down
4 changes: 4 additions & 0 deletions packages/react-moveable/stories/99-Tests/Deafult.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ group.add("Test flex element", {
app: require("./ReactFlexApp").default,
text: require("!!raw-loader!./ReactFlexApp").default,
});
group.add("Test Container with will change", {
app: require("./ReactWillChangeApp").default,
text: require("!!raw-loader!./ReactWillChangeApp").default,
});
20 changes: 20 additions & 0 deletions packages/react-moveable/stories/99-Tests/ReactWillChangeApp.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as React from "react";
import Moveable from "@/react-moveable";

export default function App() {
return <div className="no-container">
<div className="will-change-container">
{/* <div className="will-change-inner"> */}
<div className="will-change-target">Target1</div>
{/* </div> */}
</div>
<Moveable
target={".will-change-target"}
draggable={true}
preventClickDefault={true}
onDrag={e => {
e.target.style.transform = e.transform;
}}
/>
</div>;
}
17 changes: 17 additions & 0 deletions packages/react-moveable/stories/templates/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ html, body {
position: relative;
margin-top: 50px;
}
.will-change-container {
padding-left: 100px;
padding-top: 100px;
will-change: transform;
}
.will-change-target {
position: relative;
width: 100px;
height: 100px;
line-height: 100px;
text-align: center;
background: #ee8;
color: #333;
font-weight: bold;
border: 1px solid #333;
box-sizing: border-box;
}
.target {
position: absolute;
width: 100px;
Expand Down

0 comments on commit cd1de86

Please sign in to comment.