Skip to content

Commit

Permalink
fix(esl-drag-to-scroll): fix propagation of the click if drag detected
Browse files Browse the repository at this point in the history
Cosmetic: update methods visibility for inheritors
  • Loading branch information
ala-n committed Oct 21, 2024
1 parent c98cfa4 commit 0b4aee6
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/modules/esl-drag-to-scroll/core/esl-drag-to-scroll.mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,18 @@ export class ESLDragToScrollMixin extends ESLMixinElement {
};

/** Initial pointer event when dragging starts */
private startEvent: PointerEvent;
protected startEvent: PointerEvent;

private startScrollLeft: number = 0;
private startScrollTop: number = 0;
protected startScrollLeft: number = 0;
protected startScrollTop: number = 0;

private _isDragging: boolean = false;

/** Flag indicating whether dragging is in progress */
public get isDragging(): boolean {
return this._isDragging;
}
private set isDragging(value: boolean) {
protected set isDragging(value: boolean) {
this._isDragging = value;
this.$$cls(this.config.cls, value);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ export class ESLDragToScrollMixin extends ESLMixinElement {

/** Handles the pointerdown event to start dragging */
@listen('pointerdown')
private onPointerDown(event: PointerEvent): void {
protected onPointerDown(event: PointerEvent): void {
this.startEvent = event;
this.startScrollLeft = this.$host.scrollLeft;
this.startScrollTop = this.$host.scrollTop;
Expand All @@ -116,7 +116,7 @@ export class ESLDragToScrollMixin extends ESLMixinElement {

/** Handles the pointermove event to perform scrolling while dragging */
@listen({auto: false, event: 'pointermove', group: 'pointer'})
private onPointerMove(event: PointerEvent): void {
protected onPointerMove(event: PointerEvent): void {
const offset = this.getEventOffset(event);

if (!this.isDragging) {
Expand All @@ -133,7 +133,7 @@ export class ESLDragToScrollMixin extends ESLMixinElement {

/** Handles the pointerup and pointercancel events to stop dragging */
@listen({auto: false, event: 'pointerup pointercancel', group: 'pointer'})
private onPointerUp(event: PointerEvent): void {
protected onPointerUp(event: PointerEvent): void {
this.$$off({group: 'pointer'});
if (this.$host.hasPointerCapture(event.pointerId)) {
this.$host.releasePointerCapture(event.pointerId);
Expand All @@ -143,8 +143,10 @@ export class ESLDragToScrollMixin extends ESLMixinElement {
setTimeout(() => this.isDragging = false);
}

@listen('click')
private onClick(event: MouseEvent): void {
if (this.isDragging) event.preventDefault();
@listen({event: 'click', capture: true})
protected onClick(event: MouseEvent): void {
if (!this.isDragging) return;
event.preventDefault();
event.stopPropagation();
}
}

0 comments on commit 0b4aee6

Please sign in to comment.