Skip to content

Commit

Permalink
fix(react): uishell headermenu blur handler (#14616)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com>
  • Loading branch information
cordesmj and andreancardona committed Sep 12, 2023
1 parent 149fc26 commit 7d95369
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,15 @@
"contributions": [
"code"
]
},
{
"login": "cordesmj",
"name": "cordesmj",
"avatar_url": "https://avatars.githubusercontent.com/u/7409239?v=4",
"profile": "https://github.com/cordesmj",
"contributions": [
"code"
]
}
],
"commitConvention": "none"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
<tr>
<td align="center"><a href="https://github.com/djragsdale"><img src="https://avatars.githubusercontent.com/u/4396766?v=4?s=100" width="100px;" alt=""/><br /><sub><b>David Ragsdale</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=djragsdale" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/haocheng6"><img src="https://avatars.githubusercontent.com/u/7645930?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Hao Cheng</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=haocheng6" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/cordesmj"><img src="https://avatars.githubusercontent.com/u/7409239?v=4?s=100" width="100px;" alt=""/><br /><sub><b>cordesmj</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=cordesmj" title="Code">💻</a></td>
</tr>
</table>

Expand Down
25 changes: 11 additions & 14 deletions packages/react/src/components/UIShell/HeaderMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,22 @@ class HeaderMenu extends React.Component {

/**
* Handle our blur event from our underlying menuitems. Will mostly be used
* for toggling the expansion status of our menu in response to a user
* clicking off of the menu or menubar.
* for closing our menu in response to a user clicking off or tabbing out of
* the menu or menubar.
*/
handleOnBlur = (event) => {
// Rough guess for a blur event that is triggered outside of our menu or
// menubar context
const itemTriggeredBlur = this.items.find(
// Close the menu on blur when the related target is not a sibling menu item
// or a child in a submenu
const siblingItemBlurredTo = this.items.find(
(element) => element === event.relatedTarget
);
if (
event.relatedTarget &&
((event.relatedTarget.getAttribute('href') &&
event.relatedTarget.getAttribute('href') !== '#') ||
itemTriggeredBlur)
) {
return;
}
const childItemBlurredTo = this._subMenus.current?.contains(
event.relatedTarget
);

this.setState({ expanded: false, selectedIndex: null });
if (!siblingItemBlurredTo && !childItemBlurredTo) {
this.setState({ expanded: false, selectedIndex: null });
}
};

/**
Expand Down

0 comments on commit 7d95369

Please sign in to comment.