diff --git a/client/components/Nav.jsx b/client/components/Nav.jsx index 725c39e5..0aad07a1 100644 --- a/client/components/Nav.jsx +++ b/client/components/Nav.jsx @@ -55,14 +55,16 @@ class Nav extends React.PureComponent { this.handleFocusForHelp = this.handleFocus.bind(this, 'help'); this.toggleDropdownForAccount = this.toggleDropdown.bind(this, 'account'); this.handleFocusForAccount = this.handleFocus.bind(this, 'account'); + this.closeDropDown = this.closeDropDown.bind(this); } - componentWillMount() { + componentDidMount() { document.addEventListener('mousedown', this.handleClick, false); + document.addEventListener('keydown', this.closeDropDown, false); } - componentWillUnmount() { document.removeEventListener('mousedown', this.handleClick, false); + document.removeEventListener('keydown', this.closeDropDown, false); } setDropdown(dropdown) { @@ -71,8 +73,17 @@ class Nav extends React.PureComponent { }); } + closeDropDown(e) { + if (e.keyCode === 27) { + this.setDropdown('none'); + } + } + handleClick(e) { - if (this.node.contains(e.target)) { + if (!this.node) { + return; + } + if (this.node && this.node.contains(e.target)) { return; } @@ -233,25 +244,23 @@ class Nav extends React.PureComponent {