Skip to content

Commit

Permalink
close drawer when a link is clicked (elastic#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Keairns authored and chandlerprall committed Mar 28, 2019
1 parent 7014eb3 commit 95434b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `6.10.6`.
- Changed `EuiNavDrawer` to close on any link click ([#1773](https://github.com/elastic/eui/pull/1773))

## [`6.10.6`](https://github.com/elastic/eui/tree/v6.10.6)

Expand Down
18 changes: 17 additions & 1 deletion src/components/nav_drawer/nav_drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,22 @@ export class EuiNavDrawer extends Component {
this.collapseFlyout();
}

handleDrawerMenuClick = e => {
// walk up e.target until either:
// 1. a[href] - close the menu
// 2. document.body - do nothing

let element = e.target;
while (element !== undefined && element !== document.body && (element.tagName !== 'A' || element.getAttribute('href') === undefined)) {
element = element.parentElement;
}

if (element !== document.body) {
// this is an anchor with an href
this.closeBoth();
}
}

render() {
const {
children,
Expand Down Expand Up @@ -214,7 +230,7 @@ export class EuiNavDrawer extends Component {
{...rest}
>
<EuiFlexItem grow={false}>
<div id="navDrawerMenu" className={menuClasses}>
<div id="navDrawerMenu" className={menuClasses} onClick={this.handleDrawerMenuClick}>
{/* Put expand button first so it's first in tab order then on toggle starts the tabbing of the items from the top */}
{/* TODO: Add a "skip navigation" keyboard only button */}
{footerContent}
Expand Down

0 comments on commit 95434b9

Please sign in to comment.