Skip to content

Commit

Permalink
[docs-infra] Fix product selector popup not closing on route change (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
divyammadhok committed Feb 23, 2024
1 parent 10e57d7 commit 1d02294
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/src/modules/components/AppNavDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const savedScrollTop = {};

function ProductDrawerButton(props) {
const [anchorEl, setAnchorEl] = React.useState(null);

const open = Boolean(anchorEl);
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
Expand All @@ -54,6 +55,15 @@ function ProductDrawerButton(props) {
setAnchorEl(null);
};

const handleEventDelegation = (event) => {
// Assert whether an 'a' tag resides in the parent of the clicked element through which the event bubbles out.
const isLinkInParentTree = Boolean(event.target.closest('a'));
// If the element clicked is link or just inside of a link element then close the menu.
if (isLinkInParentTree) {
handleClose();
}
};

return (
<React.Fragment>
<Button
Expand Down Expand Up @@ -93,6 +103,7 @@ function ProductDrawerButton(props) {
width: { xs: 340, sm: 'auto' },
},
}}
onClick={handleEventDelegation}
>
<MuiProductSelector />
</Menu>
Expand Down

0 comments on commit 1d02294

Please sign in to comment.