Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrollbar errors when offset is zero #724

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

pradeepnschrodinger
Copy link
Collaborator

Description

This fixes the issue seen at #723.
The onmousedown handler for Scrollbar throws an error when the user tries to scroll at the beginning of the scroll content area, which happens because targetTouches is undefined at:

getTouchX = (/*object*/ e) => {
return Math.round(
e.targetTouches[0].clientX - e.target.getBoundingClientRect().x
);
};
getTouchY = (/*object*/ e) => {
return Math.round(
e.targetTouches[0].clientY - e.target.getBoundingClientRect().y
);
};

because we're actually doing a normal mouse click instead of a "touch" click.
But the code shouldn't have reached here in the first place.

The root problem is that FDT thinks it's a touch event because of the way we use the || operator in

let position = this.state.isHorizontal
? nativeEvent.offsetX ||
nativeEvent.layerX ||
this.getTouchX(nativeEvent)
: nativeEvent.offsetY ||
nativeEvent.layerY ||
this.getTouchY(nativeEvent);

We should instead use the ?? operator for cases like this.

Motivation and Context

Fixes #723

How Has This Been Tested?

Tested on local examples

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@pradeepnschrodinger
Copy link
Collaborator Author

@karry08 , friendly ping

@karry08
Copy link
Collaborator

karry08 commented Jun 24, 2024

lgtm

@pradeepnschrodinger pradeepnschrodinger merged commit 0fd29dd into master Jun 24, 2024
10 checks passed
@pradeepnschrodinger pradeepnschrodinger deleted the fix-scroll-offset-at-zero branch June 24, 2024 09:05
@pradeepnschrodinger
Copy link
Collaborator Author

Released with v2.0.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type error if to click at the very beginning of the scrollbar with lots of items
2 participants