Skip to content

Commit

Permalink
fix: provide onClick feature
Browse files Browse the repository at this point in the history
Provide onClick facility for all the kind of menus
VAN-1914
  • Loading branch information
Ahtesham Quraish authored and arbrandes committed May 7, 2024
1 parent 0415c00 commit 59db41c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/DesktopHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class DesktopHeader extends React.Component {
submenuContent,
disabled,
isActive,
onClick,
} = menuItem;

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

return (
<Menu key={`${type}-${content}`} tag="div" className="nav-item" respondToPointerEvents>
<MenuTrigger tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
<MenuTrigger onClick={onClick || null} tag="a" className="nav-link d-inline-flex align-items-center" href={href}>
{content} <CaretIcon role="img" aria-hidden focusable="false" />
</MenuTrigger>
<MenuContent className="pin-left pin-right shadow py-2">
Expand Down Expand Up @@ -94,12 +96,13 @@ class DesktopHeader extends React.Component {
<React.Fragment key={index}>
{group.heading && <div className="dropdown-header" role="heading" aria-level="1">{group.heading}</div>}
{group.items.map(({
type, content, href, disabled, isActive,
type, content, href, disabled, isActive, onClick,
}) => (
<a
className={`dropdown-${type}${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
key={`${type}-${content}`}
href={href}
onClick={onClick || null}
>
{content}
</a>
Expand Down Expand Up @@ -184,6 +187,7 @@ DesktopHeader.propTypes = {
href: PropTypes.string,
content: PropTypes.string,
isActive: PropTypes.bool,
onClick: PropTypes.func,
})),
})),
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({
Expand Down
8 changes: 6 additions & 2 deletions src/MobileHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MobileHeader extends React.Component {
submenuContent,
disabled,
isActive,
onClick,
} = menuItem;

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

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

return userMenu.map((group) => (
group.items.map(({
type, content, href, disabled, isActive,
type, content, href, disabled, isActive, onClick,
}) => (
<li className="nav-item" key={`${type}-${content}`}>
<a
className={`nav-link${isActive ? ' active' : ''}${disabled ? ' disabled' : ''}`}
href={href}
onClick={onClick || null}
>
{content}
</a>
Expand Down Expand Up @@ -192,6 +195,7 @@ MobileHeader.propTypes = {
href: PropTypes.string,
content: PropTypes.string,
isActive: PropTypes.bool,
onClick: PropTypes.func,
})),
})),
loggedOutItems: PropTypes.arrayOf(PropTypes.shape({
Expand Down
2 changes: 2 additions & 0 deletions src/__snapshots__/Header.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ exports[`<Header /> renders correctly for anonymous desktop 1`] = `
<a
className="nav-link"
href="http://localhost:18000/dashboard"
onClick={null}
>
Courses
</a>
Expand Down Expand Up @@ -229,6 +230,7 @@ exports[`<Header /> renders correctly for authenticated desktop 1`] = `
<a
className="nav-link"
href="http://localhost:18000/dashboard"
onClick={null}
>
Courses
</a>
Expand Down

0 comments on commit 59db41c

Please sign in to comment.