Skip to content

Commit a679dae

Browse files
authored
fix(HeaderMenu): use composeEventHandlers in HeaderMenu (#14353)
1 parent a6ae38b commit a679dae

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

packages/react/src/components/UIShell/HeaderMenu.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { keys, matches } from '../../internal/keyboard';
1313
import { AriaLabelPropType } from '../../prop-types/AriaPropTypes';
1414
import { PrefixContext } from '../../internal/usePrefix';
1515
import deprecate from '../../prop-types/deprecate';
16+
import { composeEventHandlers } from '../../tools/events';
1617

1718
/**
1819
* `HeaderMenu` is used to render submenu's in the `Header`. Most often children
@@ -57,6 +58,24 @@ class HeaderMenu extends React.Component {
5758
*/
5859
menuLinkName: PropTypes.string.isRequired,
5960

61+
/**
62+
* Optionally provide an onBlur handler that is called when the underlying
63+
* button fires it's onblur event
64+
*/
65+
onBlur: PropTypes.func,
66+
67+
/**
68+
* Optionally provide an onClick handler that is called when the underlying
69+
* button fires it's onclick event
70+
*/
71+
onClick: PropTypes.func,
72+
73+
/**
74+
* Optionally provide an onKeyDown handler that is called when the underlying
75+
* button fires it's onkeydown event
76+
*/
77+
onKeyDown: PropTypes.func,
78+
6079
/**
6180
* Optional component to render instead of string
6281
*/
@@ -190,6 +209,9 @@ class HeaderMenu extends React.Component {
190209
renderMenuContent: MenuContent,
191210
menuLinkName,
192211
focusRef, // eslint-disable-line no-unused-vars
212+
onBlur,
213+
onClick,
214+
onKeyDown,
193215
...rest
194216
} = this.props;
195217

@@ -226,9 +248,9 @@ class HeaderMenu extends React.Component {
226248
<li // eslint-disable-line jsx-a11y/mouse-events-have-key-events,jsx-a11y/no-noninteractive-element-interactions
227249
{...rest}
228250
className={itemClassName}
229-
onKeyDown={this.handleMenuClose}
230-
onClick={this.handleOnClick}
231-
onBlur={this.handleOnBlur}>
251+
onKeyDown={composeEventHandlers([onKeyDown, this.handleMenuClose])}
252+
onClick={composeEventHandlers([onClick, this.handleOnClick])}
253+
onBlur={composeEventHandlers([onBlur, this.handleOnBlur])}>
232254
<a // eslint-disable-line jsx-a11y/role-supports-aria-props,jsx-a11y/anchor-is-valid
233255
aria-haspopup="menu" // eslint-disable-line jsx-a11y/aria-proptypes
234256
aria-expanded={this.state.expanded}

0 commit comments

Comments
 (0)