Skip to content

Commit 59db41c

Browse files
Ahtesham Quraisharbrandes
authored andcommitted
fix: provide onClick feature
Provide onClick facility for all the kind of menus VAN-1914
1 parent 0415c00 commit 59db41c

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/DesktopHeader.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class DesktopHeader extends React.Component {
3333
submenuContent,
3434
disabled,
3535
isActive,
36+
onClick,
3637
} = menuItem;
3738

3839
if (type === 'item') {
@@ -41,6 +42,7 @@ class DesktopHeader extends React.Component {
4142
key={`${type}-${content}`}
4243
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
4344
href={href}
45+
onClick={onClick || null}
4446
>
4547
{content}
4648
</a>
@@ -49,7 +51,7 @@ class DesktopHeader extends React.Component {
4951

5052
return (
5153
<Menu key={`${type}-${content}`} tag="div" className="nav-item" respondToPointerEvents>
52-
<MenuTrigger tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
54+
<MenuTrigger onClick={onClick || null} tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
5355
{content} <CaretIcon role="img" aria-hidden focusable="false" />
5456
</MenuTrigger>
5557
<MenuContent className="pin-left pin-right shadow py-2">
@@ -94,12 +96,13 @@ class DesktopHeader extends React.Component {
9496
<React.Fragment key={index}>
9597
{group.heading && <div className="dropdown-header" role="heading" aria-level="1">{group.heading}</div>}
9698
{group.items.map(({
97-
type, content, href, disabled, isActive,
99+
type, content, href, disabled, isActive, onClick,
98100
}) => (
99101
<a
100102
className={`dropdown-${type}${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
101103
key={`${type}-${content}`}
102104
href={href}
105+
onClick={onClick || null}
103106
>
104107
{content}
105108
</a>
@@ -184,6 +187,7 @@ DesktopHeader.propTypes = {
184187
href: PropTypes.string,
185188
content: PropTypes.string,
186189
isActive: PropTypes.bool,
190+
onClick: PropTypes.func,
187191
})),
188192
})),
189193
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({

src/MobileHeader.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class MobileHeader extends React.Component {
3333
submenuContent,
3434
disabled,
3535
isActive,
36+
onClick,
3637
} = menuItem;
3738

3839
if (type === 'item') {
@@ -41,6 +42,7 @@ class MobileHeader extends React.Component {
4142
key={`${type}-${content}`}
4243
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
4344
href={href}
45+
onClick={onClick || null}
4446
>
4547
{content}
4648
</a>
@@ -49,7 +51,7 @@ class MobileHeader extends React.Component {
4951

5052
return (
5153
<Menu key={`${type}-${content}`} tag="div" className="nav-item">
52-
<MenuTrigger tag="a" role="button" tabIndex="0" className="nav-link">
54+
<MenuTrigger onClick={onClick || null} tag="a" role="button" tabIndex="0" className="nav-link">
5355
{content}
5456
</MenuTrigger>
5557
<MenuContent className="position-static pin-left pin-right py-2">
@@ -75,12 +77,13 @@ class MobileHeader extends React.Component {
7577

7678
return userMenu.map((group) => (
7779
group.items.map(({
78-
type, content, href, disabled, isActive,
80+
type, content, href, disabled, isActive, onClick,
7981
}) => (
8082
<li className="nav-item" key={`${type}-${content}`}>
8183
<a
8284
className={`nav-link${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
8385
href={href}
86+
onClick={onClick || null}
8487
>
8588
{content}
8689
</a>
@@ -192,6 +195,7 @@ MobileHeader.propTypes = {
192195
href: PropTypes.string,
193196
content: PropTypes.string,
194197
isActive: PropTypes.bool,
198+
onClick: PropTypes.func,
195199
})),
196200
})),
197201
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({

src/__snapshots__/Header.test.jsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ exports[`<Header /> renders correctly for anonymous desktop 1`] = `
3333
<a
3434
className="nav-link"
3535
href="http://localhost:18000/dashboard"
36+
onClick={null}
3637
>
3738
Courses
3839
</a>
@@ -229,6 +230,7 @@ exports[`<Header /> renders correctly for authenticated desktop 1`] = `
229230
<a
230231
className="nav-link"
231232
href="http://localhost:18000/dashboard"
233+
onClick={null}
232234
>
233235
Courses
234236
</a>

0 commit comments

Comments
 (0)