Skip to content

Commit

Permalink
Merge pull request #60 from brigade/rename-scrollable-parent
Browse files Browse the repository at this point in the history
Rename `scrollableParent` prop to `scrollableAncestor`
  • Loading branch information
trotzig committed Feb 15, 2016
2 parents e9e32f3 + 057e6b0 commit a15324f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## master (unreleased)
- Rename `scrollableParent` prop to `scrollableAncestor`

## 1.2.1
- Make bundled waypoint.js easier to import
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ can then use a `key` prop to control when a waypoint is reused vs. re-created.
threshold: PropTypes.number,

/**
* Scrollable Parent - A custom parent to determine if the
* Scrollable Ancestor - A custom ancestor to determine if the
* target is visible in it. This is useful in cases where
* you do not want the immediate scrollable ancestor to be
* the container. For example, when your target is in a div
* that has overflow auto but you are detecting onEnter based
* on the window.
*/
scrollableParent: PropTypes.any,
scrollableAncestor: PropTypes.any,

/**
* FireOnRapidScroll - if the onEnter/onLeave events are to be fired
Expand Down
10 changes: 10 additions & 0 deletions spec/waypoint_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,4 +487,14 @@ describe('<Waypoint>', function() {
});
});
});

describe('when using the legacy `scrollableParent` prop', () => {
beforeEach(() => {
this.props.scrollableParent = window;
});

it('throws a helpful error', () => {
expect(this.subject).toThrowError(/changed name to `scrollableAncestor`/);
});
});
});
16 changes: 12 additions & 4 deletions src/waypoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const propTypes = {
onEnter: PropTypes.func,
onLeave: PropTypes.func,
fireOnRapidScroll: PropTypes.bool,
scrollableParent: PropTypes.any,
scrollableAncestor: PropTypes.any,
};

const defaultProps = {
Expand All @@ -28,6 +28,13 @@ const defaultProps = {
* Calls a function when you scroll to the element.
*/
export default class Waypoint extends React.Component {
componentWillMount() {
if (this.props.scrollableParent) { // eslint-disable-line react/prop-types
throw new Error('The `scrollableParent` prop has changed name ' +
'to `scrollableAncestor`.');
}
}

componentDidMount() {
if (!Waypoint.getWindow()) {
return;
Expand Down Expand Up @@ -73,8 +80,8 @@ export default class Waypoint extends React.Component {
* as a fallback.
*/
_findScrollableAncestor() {
if (this.props.scrollableParent) {
return this.props.scrollableParent;
if (this.props.scrollableAncestor) {
return this.props.scrollableAncestor;
}

let node = ReactDOM.findDOMNode(this);
Expand Down Expand Up @@ -133,7 +140,8 @@ export default class Waypoint extends React.Component {
currentPosition === POSITIONS.above;
const isRapidScrollUp = previousPosition === POSITIONS.above &&
currentPosition === POSITIONS.below;
if (this.props.fireOnRapidScroll && (isRapidScrollDown || isRapidScrollUp)) {
if (this.props.fireOnRapidScroll &&
(isRapidScrollDown || isRapidScrollUp)) {
// If the scroll event isn't fired often enough to occur while the
// waypoint was visible, we trigger both callbacks anyway.
this.props.onEnter.call(this, event, previousPosition);
Expand Down

0 comments on commit a15324f

Please sign in to comment.