Skip to content

Commit

Permalink
feat(esl-event-listener): add ability to prevent default wheel action…
Browse files Browse the repository at this point in the history
… trough ESLWheelTarget
  • Loading branch information
ala-n committed Jun 27, 2024
1 parent 766dabe commit 0e1f192
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/esl-event-listener/core/targets/wheel.target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface ESLWheelTargetSetting {
timeout?: number;
/** Predicate to ignore wheel events */
ignore?: Predicate<WheelEvent>;
/** Prevent default action for wheel event */
preventDefault?: boolean;
}

/**
Expand All @@ -37,6 +39,7 @@ export class ESLWheelTarget extends SyntheticEventTarget {
skipOnScroll: true,
distance: 400,
timeout: 100,
preventDefault: false,
ignore: () => false
};

Expand Down Expand Up @@ -79,6 +82,7 @@ export class ESLWheelTarget extends SyntheticEventTarget {
const offsets = getParentScrollOffsets(event.target as Element, this.target);
this.scrollData = this.scrollData.concat(offsets);
}
if (this.config.preventDefault) event.preventDefault();
this.aggregateWheel(event);
}

Expand Down Expand Up @@ -148,7 +152,11 @@ export class ESLWheelTarget extends SyntheticEventTarget {
super.addEventListener(event, callback);

if (this.getEventListeners().length > 1) return;
ESLEventListener.subscribe(this, this._onWheel, {event: 'wheel', capture: false, target: this.target});
ESLEventListener.subscribe(this, this._onWheel, {
event: 'wheel',
passive: !this.config.preventDefault,
target: this.target
});
}

/** Unsubscribes from the observed target {@link Element} wheel events */
Expand Down

0 comments on commit 0e1f192

Please sign in to comment.