Skip to content

Commit e7724a7

Browse files
fix: add onclick facility (#568)
Description: Add facility of onClick event on header menus VAN-1914
1 parent 36d34ec commit e7724a7

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/DesktopHeader.jsx

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

3940
if (type === 'item') {
@@ -42,6 +43,7 @@ class DesktopHeader extends React.Component {
4243
key={`${type}-${content}`}
4344
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
4445
href={href}
46+
onClick={onClick || null}
4547
>
4648
{content}
4749
</a>
@@ -50,7 +52,7 @@ class DesktopHeader extends React.Component {
5052

5153
return (
5254
<Menu key={`${type}-${content}`} tag="div" className="nav-item" respondToPointerEvents>
53-
<MenuTrigger tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
55+
<MenuTrigger onClick={onClick || null} tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
5456
{content} <CaretIcon role="img" aria-hidden focusable="false" />
5557
</MenuTrigger>
5658
<MenuContent className="pin-left pin-right shadow py-2">
@@ -107,11 +109,12 @@ class DesktopHeader extends React.Component {
107109
<React.Fragment key={index}>
108110
{group.heading && <Dropdown.Header>{group.heading}</Dropdown.Header>}
109111
{group.items.map(({
110-
type, content, href, disabled, isActive,
112+
type, content, href, disabled, isActive, onClick,
111113
}) => (
112114
<Dropdown.Item
113115
key={`${type}-${content}`}
114116
href={href}
117+
onClick={onClick || null}
115118
className={`${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
116119
>
117120
{content}
@@ -198,6 +201,7 @@ DesktopHeader.propTypes = {
198201
content: PropTypes.string,
199202
disabled: PropTypes.bool,
200203
isActive: PropTypes.bool,
204+
onClick: PropTypes.func,
201205
})),
202206
})),
203207
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({

src/MobileHeader.jsx

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

3940
if (type === 'item') {
@@ -42,6 +43,7 @@ class MobileHeader extends React.Component {
4243
key={`${type}-${content}`}
4344
className={`nav-link${disabled ? ' disabled' : ''}${isActive ? ' active' : ''}`}
4445
href={href}
46+
onClick={onClick || null}
4547
>
4648
{content}
4749
</a>
@@ -50,7 +52,7 @@ class MobileHeader extends React.Component {
5052

5153
return (
5254
<Menu key={`${type}-${content}`} tag="div" className="nav-item">
53-
<MenuTrigger tag="a" role="button" tabIndex="0" className="nav-link">
55+
<MenuTrigger onClick={onClick || null} tag="a" role="button" tabIndex="0" className="nav-link">
5456
{content}
5557
</MenuTrigger>
5658
<MenuContent className="position-static pin-left pin-right py-2">
@@ -81,12 +83,13 @@ class MobileHeader extends React.Component {
8183

8284
const userMenuItems = userMenu.map((group) => (
8385
group.items.map(({
84-
type, content, href, disabled, isActive,
86+
type, content, href, disabled, isActive, onClick,
8587
}) => (
8688
<li className="nav-item" key={`${type}-${content}`}>
8789
<a
8890
className={`nav-link${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
8991
href={href}
92+
onClick={onClick || null}
9093
>
9194
{content}
9295
</a>
@@ -201,6 +204,7 @@ MobileHeader.propTypes = {
201204
content: PropTypes.string,
202205
disabled: PropTypes.bool,
203206
isActive: PropTypes.bool,
207+
onClick: PropTypes.func,
204208
})),
205209
})),
206210
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({

src/__snapshots__/Header.test.jsx.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,21 @@ exports[`<Header /> renders correctly for authenticated users on desktop 1`] = `
138138
<a
139139
className="nav-link"
140140
href="http://localhost:18000/dashboard"
141+
onClick={null}
141142
>
142143
Courses
143144
</a>
144145
<a
145146
className="nav-link"
146147
href="http://localhost:18000/dashboard/programs"
148+
onClick={null}
147149
>
148150
Programs
149151
</a>
150152
<a
151153
className="nav-link"
152154
href="http://localhost:18000/course"
155+
onClick={[Function]}
153156
>
154157
Discover New
155158
</a>
@@ -334,18 +337,21 @@ exports[`<Header /> renders correctly for unauthenticated users on desktop 1`] =
334337
<a
335338
className="nav-link"
336339
href="http://localhost:18000/dashboard"
340+
onClick={null}
337341
>
338342
Courses
339343
</a>
340344
<a
341345
className="nav-link"
342346
href="http://localhost:18000/dashboard/programs"
347+
onClick={null}
343348
>
344349
Programs
345350
</a>
346351
<a
347352
className="nav-link"
348353
href="http://localhost:18000/course"
354+
onClick={[Function]}
349355
>
350356
Discover New
351357
</a>

0 commit comments

Comments
 (0)