Skip to content

Commit

Permalink
close drawer when a link is clicked (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Keairns authored Mar 27, 2019
1 parent 2677d10 commit 4ae760c
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 `9.6.0`.
- Changed `EuiNavDrawer` to close on any link click ([#1773](https://github.com/elastic/eui/pull/1773))

## [`9.6.0`](https://github.com/elastic/eui/tree/v9.6.0)

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 4ae760c

Please sign in to comment.