-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Development to Main, week 40 #114
Conversation
…navigation-components
…mponents feature/OP-67/navigation-components
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍🏼
I think we should have a quick call and think about how we want to implement these sub-item changes. Left some comments on it as well.
const screenWidth = window.innerWidth; | ||
|
||
React.useEffect(() => { | ||
if (screenWidth > 992) { | ||
setSubNavIsOpen({}); | ||
} | ||
}, [screenWidth]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not triggering on the "right" moments. screenWidth
seems to update sometimes, I think whenever the React lifecycle is triggered by some other side effect.
To accurately keep track of a screen width, we can register (and un-register when needed) a listener, like so (dummy code):
const [screenWidth, setScreenWidth] = React.useState<number | undefined>(undefined);
React.useEffect(() => {
const handleScreenResize = (e: TypeThis) => setScreenWidth(e.path_to_width);
window.addEventListener("resize", handleScreenResize); // add listener
return () => window.removeEventListener("resize", handleScreenResize) // remove listener when component is removed
}, []) // only trigger once
@@ -26,6 +26,7 @@ export interface TopNavProps { | |||
|
|||
export const PrimaryTopNav = ({ items, mobileLogo, layoutClassName }: TopNavProps): JSX.Element => { | |||
const [isOpen, setIsOpen] = React.useState<boolean>(false); | |||
const [subNavIsOpen, setSubNavIsOpen] = React.useState({}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should type this state, it's unclear what it's expecting.
const handleSubItemMenu = (idx: number, value: boolean) => { | ||
setSubNavIsOpen({ | ||
...subNavIsOpen, | ||
[idx as keyof typeof subNavIsOpen]: value, | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a complex way to keep track of the open sub items. Previously, I think, we just let the css handle everything. Why the change?
onClick={() => | ||
!subItems | ||
? handleItemClick(handleClick) | ||
: screenWidth > 992 | ||
? handleItemClick(handleClick) | ||
: handleSubItemMenu(idx, !subNavIsOpen[idx as keyof typeof subNavIsOpen] ?? true) | ||
} | ||
className={clsx(styles.li, current && styles.current)} | ||
key={idx} | ||
> | ||
<Link className={clsx(styles.link, styles.label)}> | ||
<Link | ||
className={clsx( | ||
styles.link, | ||
styles.label, | ||
subItems && styles.mobileLink, | ||
current && styles.currentLink, | ||
)} | ||
> | ||
{icon} | ||
{label} | ||
{label}{" "} | ||
{subItems && screenWidth < 992 && ( | ||
<FontAwesomeIcon | ||
className={clsx(styles.toggleIcon, subNavIsOpen[idx as keyof typeof subNavIsOpen] && styles.isOpen)} | ||
icon={faChevronRight} | ||
/> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this a bit complex, see my other comment as well.
Is this because a top-level item can have a link and have sub-items?
feature/XW-87/select-WCAG
feature/XW-87/select-WCAG
feature/XW-87/select-WCAG
feature/OP-57/pagination
feature/OP-57/pagination
…gination Revert "feature/OP-57/pagination"
…gination Revert "feature/OP-57/pagination"
…lect-WCAG Revert "feature/XW-87/select-WCAG"
…lect-WCAG Revert "feature/XW-87/select-WCAG"
…lect-WCAG Revert "feature/XW-87/select-WCAG"
No description provided.