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

Add custom element option to WindowScroller #481

Closed
wants to merge 43 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b7ac151
Add util for abstracting API differences between window and other con…
andrewbranch Nov 22, 2016
754cb2a
Modify onScroll utils to accept arbitrary scroll element
andrewbranch Nov 22, 2016
1981162
Allow WindowScroller to receive custom scrollElement prop
andrewbranch Nov 22, 2016
b9399dd
Fix copy/paste error
andrewbranch Nov 22, 2016
a0df5f8
Look at what element scroll listener was attached to, not initiator
andrewbranch Nov 22, 2016
57efa5f
Update demo to include custom scroll element option
andrewbranch Nov 22, 2016
27f2b69
Fix case where prop changes from custom element to nothing
andrewbranch Nov 22, 2016
e06f19e
Make sure my custom element is scrolling, not ContentBox
andrewbranch Nov 22, 2016
ca60f00
Auto fix linter errors
andrewbranch Nov 22, 2016
8da79fb
Fix linter errors / things that will break server-side
andrewbranch Nov 22, 2016
6fd41a0
Update pointerEvents assertions
andrewbranch Nov 22, 2016
18612a6
Fix failing "restore pointer events on unmount" test
andrewbranch Nov 22, 2016
8ff9cfc
Add missing _updateDimensions call
andrewbranch Nov 22, 2016
dc7a7ac
Replace PropTypes.object with any for HTMLElement props
andrewbranch Nov 22, 2016
2a90fbf
Add autoprefixer-loader (for now?)
andrewbranch Nov 22, 2016
36e14b6
Prevent internal scroll position overwriting scroll position from props
Nov 23, 2016
a8f039f
Updated cellRenderer callback parameters to also match List rowRenderer
romulof Nov 29, 2016
42493ce
Update CellMeasurer documentation
romulof Nov 29, 2016
2ddaed2
Fixed code-style issue
romulof Nov 29, 2016
919e342
Updated tests for new CellMeasurer render :index param
Nov 30, 2016
197a5c3
Removed outdated warning about using CellMeasurer with List now that …
Nov 30, 2016
c7bb0b7
Updated CHANGELOG in advance of upcoming release
Nov 30, 2016
cc83019
Merge pull request #482 from lic-nz/fix-scroll-position-from-props
mbrevda Dec 1, 2016
643d8a2
Minor formatting tweaks
Dec 1, 2016
05570f8
Updated CHANGELOG for upcoming release
Dec 1, 2016
2a721a7
Prepping 8.6.0 release
Dec 1, 2016
fe11056
Revert "Add autoprefixer-loader (for now?)"
andrewbranch Dec 1, 2016
78781c7
Revert "Modify onScroll utils to accept arbitrary scroll element"
andrewbranch Dec 1, 2016
335d6df
onScroll take 2: attach listener to arbitrary scroll element, but onl…
andrewbranch Dec 1, 2016
15c9fde
Revert "Update pointerEvents assertions"
andrewbranch Dec 1, 2016
bb804f2
Fix clearTimeout never being called
andrewbranch Dec 1, 2016
29cec61
Update CellSizeCache interface for better perfomance (#486)
arusakov Dec 1, 2016
5c2b141
Merge branch 'arusakov-486_cell_size_cache_optimisation'
Dec 2, 2016
d44dde1
Prepping for 8.6.1 release
Dec 2, 2016
188d691
Fix checkbox bug/typo
andrewbranch Dec 2, 2016
43691da
Fix demo bug: make sure container does not shrink when Grid is not ye…
andrewbranch Dec 2, 2016
c86015e
Fix bug where new height was calculated with old element (never changed)
andrewbranch Dec 2, 2016
2e91ec7
Added to to handle case when header items change or resize. also b…
Dec 3, 2016
32454e0
Reverted part of the change introduced in version 8.6.0 that changed …
Dec 3, 2016
36a54f9
Resolved conflicts
Dec 3, 2016
87fe0f1
Fix positionFromTop calculation
andrewbranch Dec 15, 2016
f2199ac
Add scroll handlers to distinct scrollElements
andrewbranch Dec 22, 2016
7c78188
Avoid some unnecessary updates to some WindowScrollers
andrewbranch Jan 11, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add util for abstracting API differences between window and other con…
…tainers
andrewbranch committed Nov 22, 2016
commit b7ac15184eafdaa0fa0aff7936b2f8b982645cc2
30 changes: 30 additions & 0 deletions source/WindowScroller/utils/dimensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Gets the vertical scroll amount of the element, accounting for IE compatibility
* and API differences between `window` and other DOM elements.
*/
export function getVerticalScroll (element) {
return element === window
? (('scrollY' in window) ? window.scrollY : document.documentElement.scrollTop)
: element.scrollTop
}

/**
* Gets the height of the element, accounting for API differences between
* `window` and other DOM elements.
*/
export function getHeight (element) {
return element === window
? window.innerHeight
: element.getBoundingClientRect().height
}

/**
* Gets the vertical position of an element within its scroll container.
* Elements that have been “scrolled past” return negative values.
* Handles edge-case where a user is navigating back (history) from an already-scrolled page.
* In this case the body’s top position will be a negative number and this element’s top will be increased (by that amount).
*/
export function getPositionFromTop (element, container) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was having trouble wrapping my mind around this (previously here), so extra care in making sure this satisfies the original intention is appreciated.

Copy link
Owner

Choose a reason for hiding this comment

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

Okay. When I do a real review, I'll read this one carefully.

const containerElement = container === window ? document.documentElement : container
return element.getBoundingClientRect().top - container.getBoundingClientRect().top
}