Skip to content

Commit

Permalink
fix: stop propagation for click control #690
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jul 14, 2022
1 parent c937f4f commit 1a8f697
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ export default class MoveableManager<T = {}>
public onPreventClick = (e: any) => {
e.stopPropagation();
e.preventDefault();
removeEvent(window, "click", this.onPreventClick, true);
console.log("PRE");
// removeEvent(window, "click", this.onPreventClick, true);
}
public checkUpdateRect = () => {
if (this.isDragging()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ export function getAbleGesto(
};
const gesto = new Gesto(target!, options);

const isControl = eventAffix === "Control";

["drag", "pinch"].forEach(eventOperation => {
["Start", "", "End"].forEach(eventType => {
gesto.on(`${eventOperation}${eventType}` as any, e => {
Expand All @@ -218,6 +220,8 @@ export function getAbleGesto(

if (!result) {
e.stop();
} else if (eventType === "Start" && isControl) {
e?.inputEvent?.stopPropagation();
}
});
});
Expand Down
11 changes: 7 additions & 4 deletions packages/react-moveable/stories/9Z-etc/apps/ClickApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ export default function App(props: Record<string, any>) {

return (
<div className="root">
<div className="container">
<div className="container" onClick={() => {
console.log("Click");
}} onMouseDown={() => {
console.log("MouseDown");
}}>
<div className="target" ref={targetRef}>Target</div>
<Moveable
ref={moveableRef}
target={targetRef}
resizable={true}
preventClickDefault={true}
onDrag={e => {
e.target.style.transform = e.transform;
}}
onClick={() => {
alert("Click DragArea");
}}
/>
</div>
</div>
Expand Down

0 comments on commit 1a8f697

Please sign in to comment.