react-scroll-up
Advanced tools
Comparing version 1.3.3 to 1.3.4
@@ -0,1 +1,5 @@ | ||
# [1.3.4] | ||
* **Feature:** Add onShow and onHide react props | ||
# [1.3.3] | ||
@@ -2,0 +6,0 @@ |
30
index.js
@@ -94,2 +94,26 @@ /** | ||
/** | ||
* call onShow callback if passed valid props | ||
*/ | ||
}, { | ||
key: 'notifyOnShow', | ||
value: function notifyOnShow() { | ||
if (this.props.onShow && typeof this.props.onShow === "function") { | ||
this.props.onShow(); | ||
} | ||
} | ||
/** | ||
* call onHide callback if passed valid props | ||
*/ | ||
}, { | ||
key: 'notifyOnHide', | ||
value: function notifyOnHide() { | ||
if (this.props.onHide && typeof this.props.onHide === "function") { | ||
this.props.onHide(); | ||
} | ||
} | ||
/** | ||
* Evaluate show/hide this component, depend on new position | ||
@@ -104,2 +128,3 @@ */ | ||
this.setState({ show: true }); | ||
this.notifyOnShow(); | ||
} | ||
@@ -109,2 +134,3 @@ } else { | ||
this.setState({ show: false }); | ||
this.notifyOnHide(); | ||
} | ||
@@ -216,3 +242,5 @@ } | ||
duration: _propTypes2.default.number, // seconds | ||
style: _propTypes2.default.object | ||
style: _propTypes2.default.object, | ||
onShow: _propTypes2.default.func, | ||
onHide: _propTypes2.default.func | ||
}; |
{ | ||
"name": "react-scroll-up", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "React component to render element for scroll to top of page", | ||
@@ -5,0 +5,0 @@ "author": "Milos Janda <milos.janda@gmail.com>", |
@@ -59,2 +59,10 @@ # react-scroll-up | ||
### onShow:function (optional) | ||
Callback function to be called when the button is being displayed. | ||
### onHide:function (optional) | ||
Callback function to be called when the button is being hidden. | ||
### style:object (optional) | ||
@@ -61,0 +69,0 @@ |
@@ -269,2 +269,53 @@ // JSDom is used to allow the tests to run right from the command line (no browsers needed) | ||
// describe makes a test group | ||
describe('<ScrollUp/> onShow onHide props', function () { | ||
// This will be run before each test to reset the scroll position | ||
beforeEach(() => { | ||
window.pageYOffset = 0; | ||
}); | ||
it('check onShow callback is working properly', function () { | ||
let calledOnShow = false; | ||
let renderedComponent = TestUtils.renderIntoDocument( | ||
<ScrollUp showUnder={100} onShow={() => { calledOnShow = true }}> | ||
<span>UP</span> | ||
</ScrollUp> | ||
); | ||
// is hidden when first rendered | ||
expect(renderedComponent.state.show).to.be.false; | ||
// Set the scroll position to 200 and trigger the event manually | ||
window.pageYOffset = 200; | ||
renderedComponent.handleScroll(); | ||
expect(renderedComponent.state.show).to.be.true; // button is now displayed | ||
expect(calledOnShow).to.be.true; // and callback was called | ||
}); | ||
it('check onHide callback is working properly', function () { | ||
let calledOnHide = false; | ||
let renderedComponent = TestUtils.renderIntoDocument( | ||
<ScrollUp showUnder={100} onHide={() => { calledOnHide = true }}> | ||
<span>UP</span> | ||
</ScrollUp> | ||
); | ||
// is hidden when first rendered | ||
expect(renderedComponent.state.show).to.be.false; | ||
// Set the scroll position to 200 and trigger the event manually | ||
window.pageYOffset = 200; | ||
renderedComponent.handleScroll(); | ||
expect(renderedComponent.state.show).to.be.true; // button is now displayed | ||
expect(calledOnHide).to.be.false; // and callback was not yet called | ||
// Set the scroll position to 50 and trigger the event manually | ||
window.pageYOffset = 50; | ||
renderedComponent.handleScroll(); | ||
expect(renderedComponent.state.show).to.be.false; // button is now hidden | ||
expect(calledOnHide).to.be.true; // and callback was called | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26350
438
89
7