Skip to content

Commit

Permalink
[B] Minor header nav fixes
Browse files Browse the repository at this point in the history
 - Constrain dropdown width to avoid overflow-x edge case
 - Eliminate scroll bar flash on accordion hieght transition
 - Refactor extra useEffect for micro-managing header nav visibility on scroll
  • Loading branch information
Blake Mason authored and blnkt committed Apr 17, 2024
1 parent 5439030 commit e7c2f66
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
14 changes: 6 additions & 8 deletions components/global/Header/Navigation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useState, useRef } from "react";
import { useState, useRef } from "react";
import PropTypes from "prop-types";
import classNames from "classnames";
import { useTranslation } from "react-i18next";
Expand All @@ -13,7 +13,7 @@ export default function Navigation({
items,
userProfilePage,
theme,
isOpenSetter,
desktopSetter,
mobileActive,
mobileSetter,
}) {
Expand All @@ -28,10 +28,6 @@ export default function Navigation({

useClickEvent(handleClick);

useEffect(() => {
if (isOpenSetter) isOpenSetter(!!active);
}, [mobileSetter, isOpenSetter, active]);

function handleClick(e) {
const isLink =
e.target.nodeName === "A" || e.target.parentElement?.nodeName === "A";
Expand All @@ -42,15 +38,17 @@ export default function Navigation({
}
if (navList?.current?.contains(e.target)) return;
setActive(null);
if (desktopSetter) desktopSetter(false);
}

function handleToggleClick(id) {
setActive((prevActive) => (prevActive === id ? null : id));
if (desktopSetter) desktopSetter(true);
}

function handleSignOut() {
setActive(null);
mobileSetter(false);
if (mobileSetter) mobileSetter(false);
signOut();
}

Expand Down Expand Up @@ -165,7 +163,7 @@ Navigation.propTypes = {
items: PropTypes.arrayOf(internalLinkWithChildrenShape),
userProfilePage: PropTypes.object,
theme: PropTypes.oneOf(["desktop", "mobile"]),
isOpenSetter: PropTypes.func,
desktopSetter: PropTypes.func,
mobileActive: PropTypes.bool,
mobileSetter: PropTypes.func,
};
Expand Down
12 changes: 10 additions & 2 deletions components/global/Header/_subsubnavigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@ $_button-bg-color: functions.sass-palette(neutral02);
height: 100%;
max-height: 0;
margin-left: functions.header(nav-link-padding-lateral) / 2;
overflow: auto;
overflow: hidden;
color: $_color;
visibility: hidden;
transition: max-height 0.25s ease-out, visibility 0s 0.25s;

@keyframes hide-scroll {
from, to {
overflow: hidden;
}
}

&--is-active {
max-height: calc(100vh - var(--header-height));
overflow: auto;
visibility: visible;
transition: max-height 0.5s ease-out;
transition: max-height 0.5s ease-in;
animation: hide-scroll 0.5s backwards;
}

&__item {
Expand Down
10 changes: 7 additions & 3 deletions components/global/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import SRAuthStatus from "../../auth/SRAuthStatus";

export default function Header({ navItems, userProfilePage }) {
const [mobileNavActive, setMobileNavActive] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const [desktopNavActive, setDesktopNavActive] = useState(false);
const [mobileLogoActive, setMobileLogoActive] = useState(false);
const [prevScrollPos, setPrevScrollPos] = useState(0);
const [visible, setVisible] = useState(true);
Expand Down Expand Up @@ -57,7 +57,7 @@ export default function Header({ navItems, userProfilePage }) {
<header
ref={ref}
className={`c-global-header ${
visible || mobileNavActive || isOpen ? "" : "invisible"
visible || mobileNavActive || desktopNavActive ? "" : "invisible"
}`}
>
<a href="#page-content" className="c-global-header__skip-link">
Expand All @@ -79,7 +79,11 @@ export default function Header({ navItems, userProfilePage }) {
</Link>
</div>
<nav className="c-global-header__nav-block">
<Navigation items={navItems} theme="desktop" isOpenSetter={setIsOpen} />
<Navigation
items={navItems}
theme="desktop"
desktopSetter={setDesktopNavActive}
/>
</nav>
<div className="c-global-header__search-block">
<SearchBar />
Expand Down
2 changes: 1 addition & 1 deletion theme/styles/abstracts/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ $header: (
layout-breakpoint: 1625px,
breakpoint-for-search-bar: 850px,
nav-link-padding-lateral: 1em,
nav-width-desktop: 600px,
nav-width-desktop: 450px,
nav-width-mobile: 300px,
button-width-tablet: 114px,
button-width-mobile: 60px,
Expand Down

0 comments on commit e7c2f66

Please sign in to comment.