From 59db41c61eb5eb412fceed60b389e711ff4f44c8 Mon Sep 17 00:00:00 2001 From: Ahtesham Quraish Date: Mon, 29 Apr 2024 12:06:25 +0500 Subject: [PATCH] fix: provide onClick feature Provide onClick facility for all the kind of menus VAN-1914 --- src/DesktopHeader.jsx | 8 ++++++-- src/MobileHeader.jsx | 8 ++++++-- src/__snapshots__/Header.test.jsx.snap | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/DesktopHeader.jsx b/src/DesktopHeader.jsx index c0f111fdb..05cc9372d 100644 --- a/src/DesktopHeader.jsx +++ b/src/DesktopHeader.jsx @@ -33,6 +33,7 @@ class DesktopHeader extends React.Component { submenuContent, disabled, isActive, + onClick, } = menuItem; if (type === 'item') { @@ -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} @@ -49,7 +51,7 @@ class DesktopHeader extends React.Component { return ( - + {content} @@ -94,12 +96,13 @@ class DesktopHeader extends React.Component { {group.heading &&
{group.heading}
} {group.items.map(({ - type, content, href, disabled, isActive, + type, content, href, disabled, isActive, onClick, }) => ( {content} @@ -184,6 +187,7 @@ DesktopHeader.propTypes = { href: PropTypes.string, content: PropTypes.string, isActive: PropTypes.bool, + onClick: PropTypes.func, })), })), loggedOutItems: PropTypes.arrayOf(PropTypes.shape({ diff --git a/src/MobileHeader.jsx b/src/MobileHeader.jsx index 128e2de81..f8c02fccf 100644 --- a/src/MobileHeader.jsx +++ b/src/MobileHeader.jsx @@ -33,6 +33,7 @@ class MobileHeader extends React.Component { submenuContent, disabled, isActive, + onClick, } = menuItem; if (type === 'item') { @@ -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} @@ -49,7 +51,7 @@ class MobileHeader extends React.Component { return ( - + {content} @@ -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, }) => (
  • {content} @@ -192,6 +195,7 @@ MobileHeader.propTypes = { href: PropTypes.string, content: PropTypes.string, isActive: PropTypes.bool, + onClick: PropTypes.func, })), })), loggedOutItems: PropTypes.arrayOf(PropTypes.shape({ diff --git a/src/__snapshots__/Header.test.jsx.snap b/src/__snapshots__/Header.test.jsx.snap index da50a8db5..781e7f729 100644 --- a/src/__snapshots__/Header.test.jsx.snap +++ b/src/__snapshots__/Header.test.jsx.snap @@ -33,6 +33,7 @@ exports[`
    renders correctly for anonymous desktop 1`] = ` Courses @@ -229,6 +230,7 @@ exports[`
    renders correctly for authenticated desktop 1`] = ` Courses