Skip to content

Commit 26b5e73

Browse files
emyarodtw15egankodiakhq[bot]
authored
feat(SideNav): add onOverlayClick handler (#8296)
* feat(SideNav): add onOverlayClick handler * docs(UIShell): collapse side nav on overlay click * chore: update snapshots Co-authored-by: TJ Egan <tw15egan@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent c715ff8 commit 26b5e73

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7151,6 +7151,9 @@ Map {
71517151
"isRail": Object {
71527152
"type": "bool",
71537153
},
7154+
"onOverlayClick": Object {
7155+
"type": "func",
7156+
},
71547157
"onToggle": Object {
71557158
"type": "func",
71567159
},

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const SideNav = React.forwardRef(function SideNav(props, ref) {
3333
isPersistent,
3434
addFocusListeners,
3535
addMouseListeners,
36+
onOverlayClick,
3637
...other
3738
} = props;
3839

@@ -121,7 +122,10 @@ const SideNav = React.forwardRef(function SideNav(props, ref) {
121122

122123
return (
123124
<>
124-
{isFixedNav ? null : <div className={overlayClassName} />}
125+
{isFixedNav ? null : (
126+
// eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
127+
<div className={overlayClassName} onClick={onOverlayClick} />
128+
)}
125129
<nav
126130
aria-hidden={!expanded}
127131
ref={ref}
@@ -204,6 +208,13 @@ SideNav.propTypes = {
204208
*/
205209
isRail: PropTypes.bool,
206210

211+
/**
212+
* An optional listener that is called when the SideNav overlay is clicked
213+
*
214+
* @param {object} event
215+
*/
216+
onOverlayClick: PropTypes.func,
217+
207218
/**
208219
* An optional listener that is called when an event that would cause
209220
* toggling the SideNav occurs.

packages/react/src/components/UIShell/UIShell-story.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,8 @@ export const SideNavRailWHeader = withReadme(readme, () => (
842842
<SideNav
843843
aria-label="Side navigation"
844844
isRail
845-
expanded={isSideNavExpanded}>
845+
expanded={isSideNavExpanded}
846+
onOverlayClick={onClickSideNavExpand}>
846847
<SideNavItems>
847848
<SideNavMenu renderIcon={Fade16} title="Category title">
848849
<SideNavMenuItem href="javascript:void(0)">

0 commit comments

Comments
 (0)