diff --git a/CHANGELOG.md b/CHANGELOG.md index 34e33826a3f..47a80abb942 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/components/nav_drawer/nav_drawer.js b/src/components/nav_drawer/nav_drawer.js index 1465bac1b4f..e6cdbc16541 100644 --- a/src/components/nav_drawer/nav_drawer.js +++ b/src/components/nav_drawer/nav_drawer.js @@ -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, @@ -214,7 +230,7 @@ export class EuiNavDrawer extends Component { {...rest} > -