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] Ensure valid changes on multi-scroll panes #8

Merged
merged 2 commits into from
Jul 19, 2017

Conversation

autarc
Copy link
Contributor

@autarc autarc commented Jul 17, 2017

WHAT

In the current implementation its possible that a division by 0 occurs if a sync container has multiple panes with different directions (at least one vertical and one horizontal). In this case some elements have no overflow-x or overflow-y value but a fixed value. To avoid collision a check is added to ensure only valid results will be set.

Furthermore for backwards compatibility the previous react version was added to the peer dependencies.

const { scrollTop, scrollHeight, clientHeight,
scrollLeft, scrollWidth, clientWidth } = scrolledPane
const {
scrollTop, scrollHeight, clientHeight,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please put every identifier on a new line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought its easier to read this way as the properties are grouped by context (...width / ...height) but okay 😉

@@ -82,11 +87,11 @@ export default class ScrollSync extends Component {
const paneHeight = pane.scrollHeight - clientHeight
const paneWidth = pane.scrollWidth - clientWidth
/* Adjust the scrollTop position of it accordingly */
if (vertical) {
pane.scrollTop = proportional ? (paneHeight * scrollTop) / (scrollHeight - clientHeight) : scrollTop // eslint-disable-line
if (vertical && scrollTopOffset) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think && scrollOffset > 0 will be more readable and less ambiguous or what this check is doing?

@okonet
Copy link
Owner

okonet commented Jul 18, 2017

Thanks for the PR!

@autarc
Copy link
Contributor Author

autarc commented Jul 19, 2017

@okonet Sure. Always glad to find the right tool as you're looking for a solution of a less common problem and the opportunity to contribute back 😄

Copy link
Owner

@okonet okonet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@okonet okonet merged commit 7b1e791 into okonet:master Jul 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants