Skip to content

Commit

Permalink
Limit when to prevent the default wheel event
Browse files Browse the repository at this point in the history
Only prevent the default event when there will be internal grid scroll
  • Loading branch information
gpetrioli committed May 10, 2023
1 parent d754758 commit 3f4597d
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/toast-ui.grid/src/view/bodyArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,27 @@ class BodyAreaComp extends Component<Props> {

private handleWheel = (ev: WheelEvent) => {
const currentTarget = ev.currentTarget as HTMLElement;
ev.preventDefault();
const { deltaX, deltaY } = ev;
const {
offsetHeight,
offsetWidth,
scrollHeight,
scrollWidth,
scrollTop,
scrollLeft,
} = currentTarget;

const willScrollUp = deltaY < 0 && scrollTop > 0;
const willScrollDown = deltaY > 0 && scrollTop + offsetHeight < scrollHeight;
const willScrollLeft = deltaX < 0 && scrollLeft > 0;
const willScrollRight = deltaX > 0 && scrollLeft + offsetWidth < scrollWidth;

if (willScrollUp || willScrollDown || willScrollLeft || willScrollRight) {
ev.preventDefault();
}

currentTarget.scrollTop += ev.deltaY;
currentTarget.scrollLeft += ev.deltaX;
currentTarget.scrollTop += deltaY;
currentTarget.scrollLeft += deltaX;
};

private handleScroll = (ev: UIEvent) => {
Expand Down

0 comments on commit 3f4597d

Please sign in to comment.