Skip to content

Commit

Permalink
refactor: let dragStart default to currentTarget instead of target
Browse files Browse the repository at this point in the history
If the element to be dragged consists of multiple subelements, it makes
sense to use the current target (the target where the event listener is
specified) instead of the target.
  • Loading branch information
zsoerenm committed Nov 21, 2023
1 parent 12c45bd commit 8bb8293
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/moveable/src/MoveableManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class MoveableManager extends EventEmitter<MoveableEventsParameters> {
public forceUpdate(callback?: () => any) {
this.innerMoveable!.forceUpdate(callback);
}
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.target) {
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.currentTarget) {
const innerMoveable = this.innerMoveable;
if ((innerMoveable as any).$_timer) {
this.forceUpdate();
Expand Down
2 changes: 1 addition & 1 deletion packages/react-moveable/src/MoveableIndividualGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MoveableIndividualGroup extends MoveableManager<GroupableProps & Individua
};
return requestInstant ? requester.request(param).requestEnd() : requester;
}
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.target) {
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.currentTarget) {
const inputTarget = target as HTMLElement;
const childMoveable = find(this.moveables, child => {
const target = child.getTargets()[0];
Expand Down
2 changes: 1 addition & 1 deletion packages/react-moveable/src/MoveableManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export default class MoveableManager<T = {}>
* }
* });
*/
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.target) {
public dragStart(e: MouseEvent | TouchEvent, target: EventTarget | null = e.currentTarget) {
const targetGesto = this.targetGesto;
const controlGesto = this.controlGesto;

Expand Down
2 changes: 1 addition & 1 deletion packages/react-moveable/src/gesto/getAbleGesto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export function triggerAble(
}

export function checkMoveableTarget(moveable: MoveableManagerInterface) {
return (e: { inputEvent: Event }, target: EventTarget | null = e.inputEvent.target) => {
return (e: { inputEvent: Event }, target: EventTarget | null = e.inputEvent.currentTarget) => {
const eventTarget = target as Element;
const areaElement = moveable.areaElement;
const dragTargetElement = (moveable as any)._dragTarget;
Expand Down

0 comments on commit 8bb8293

Please sign in to comment.