Skip to content

Commit

Permalink
[added] onOpen callback
Browse files Browse the repository at this point in the history
This gives you the ability to call a callback after the tray opens.
  • Loading branch information
claydiffrient committed Jul 11, 2016
1 parent 462dfbc commit afe8d85
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/components/Tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default React.createClass({
propTypes: {
isOpen: React.PropTypes.bool,
onBlur: React.PropTypes.func,
onOpen: React.PropTypes.func,
closeTimeoutMS: React.PropTypes.number,
closeOnBlur: React.PropTypes.bool,
maintainFocus: React.PropTypes.bool
Expand Down
4 changes: 4 additions & 0 deletions lib/components/TrayPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default React.createClass({
overlayClassName: PropTypes.string,
isOpen: PropTypes.bool,
onBlur: PropTypes.func,
onOpen: PropTypes.func,
closeOnBlur: PropTypes.bool,
closeTimeoutMS: PropTypes.number,
children: PropTypes.any,
Expand Down Expand Up @@ -129,6 +130,9 @@ export default React.createClass({
open() {
focusManager.markForFocusLater();
this.setState({isOpen: true}, () => {
if (this.props.onOpen) {
this.props.onOpen();
}
this.setState({afterOpen: true});
});
},
Expand Down
6 changes: 6 additions & 0 deletions lib/components/__tests__/Tray-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ describe('react-tray', function() {
}, 0);
});

it('should call onOpen when it opens', function() {
let calledOpen = false;
renderTray({isOpen: true, onOpen: function() { calledOpen = true;}});
equal(calledOpen, true);
});

it('should close on overlay click', function() {
renderTray({isOpen: true, onBlur: function() {}, closeTimeoutMS: 0});
TestUtils.Simulate.click(document.querySelector('.ReactTray__Overlay'));
Expand Down

0 comments on commit afe8d85

Please sign in to comment.