Merged in fix/SW-1742-navigation-on-mobile (pull request #1436)
fix(SW-1742): fixed issue where mobile menu is not closed when clicking on a link * fix(SW-1742): fixed issue where mobile menu is not closed when clicking on a link Approved-by: Fredrik Thorsson Approved-by: Matilda Landström
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
"use client"
|
||||||
|
import NextLink from "next/link"
|
||||||
|
import { useIntl } from "react-intl"
|
||||||
|
|
||||||
|
import useDropdownStore from "@/stores/main-menu"
|
||||||
|
|
||||||
|
import { ScandicLogoIcon } from "@/components/Icons"
|
||||||
|
import useLang from "@/hooks/useLang"
|
||||||
|
|
||||||
|
import styles from "./logoLink.module.css"
|
||||||
|
|
||||||
|
import { DropdownTypeEnum } from "@/types/components/dropdown/dropdown"
|
||||||
|
|
||||||
|
export function LogoLink() {
|
||||||
|
const lang = useLang()
|
||||||
|
const intl = useIntl()
|
||||||
|
const { toggleDropdown, isHamburgerMenuOpen } = useDropdownStore()
|
||||||
|
|
||||||
|
function handleNavigate() {
|
||||||
|
if (isHamburgerMenuOpen) {
|
||||||
|
toggleDropdown(DropdownTypeEnum.HamburgerMenu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NextLink
|
||||||
|
className={styles.logoLink}
|
||||||
|
href={`/${lang}`}
|
||||||
|
onClick={handleNavigate}
|
||||||
|
aria-label={intl.formatMessage({ id: "Back to scandichotels.com" })}
|
||||||
|
>
|
||||||
|
<ScandicLogoIcon width="103px" height="22px" color="red" />
|
||||||
|
</NextLink>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
.logoLink {
|
||||||
|
display: inline-flex;
|
||||||
|
width: auto;
|
||||||
|
}
|
||||||
@@ -14,10 +14,12 @@ import MegaMenu from "../MegaMenu"
|
|||||||
|
|
||||||
import styles from "./navigationMenuItem.module.css"
|
import styles from "./navigationMenuItem.module.css"
|
||||||
|
|
||||||
|
import { DropdownTypeEnum } from "@/types/components/dropdown/dropdown"
|
||||||
import type { NavigationMenuItemProps } from "@/types/components/header/navigationMenuItem"
|
import type { NavigationMenuItemProps } from "@/types/components/header/navigationMenuItem"
|
||||||
|
|
||||||
export default function MenuItem({ item, isMobile }: NavigationMenuItemProps) {
|
export default function MenuItem({ item, isMobile }: NavigationMenuItemProps) {
|
||||||
const { openMegaMenu, toggleMegaMenu } = useDropdownStore()
|
const { openMegaMenu, toggleMegaMenu, toggleDropdown, isHamburgerMenuOpen } =
|
||||||
|
useDropdownStore()
|
||||||
const megaMenuRef = useRef<HTMLDivElement>(null)
|
const megaMenuRef = useRef<HTMLDivElement>(null)
|
||||||
const { submenu, title, link, seeAllLink, card } = item
|
const { submenu, title, link, seeAllLink, card } = item
|
||||||
const megaMenuTitle = `${title}-${isMobile ? "mobile" : "desktop"}`
|
const megaMenuTitle = `${title}-${isMobile ? "mobile" : "desktop"}`
|
||||||
@@ -33,6 +35,12 @@ export default function MenuItem({ item, isMobile }: NavigationMenuItemProps) {
|
|||||||
toggleMegaMenu(false)
|
toggleMegaMenu(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function handleNavigate() {
|
||||||
|
if (isHamburgerMenuOpen) {
|
||||||
|
toggleDropdown(DropdownTypeEnum.HamburgerMenu)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return submenu.length ? (
|
return submenu.length ? (
|
||||||
<>
|
<>
|
||||||
<MainMenuButton
|
<MainMenuButton
|
||||||
@@ -74,6 +82,7 @@ export default function MenuItem({ item, isMobile }: NavigationMenuItemProps) {
|
|||||||
className={`${styles.navigationMenuItem} ${isMobile ? styles.mobile : styles.desktop}`}
|
className={`${styles.navigationMenuItem} ${isMobile ? styles.mobile : styles.desktop}`}
|
||||||
variant="navigation"
|
variant="navigation"
|
||||||
weight="bold"
|
weight="bold"
|
||||||
|
onClick={handleNavigate}
|
||||||
href={link!.url}
|
href={link!.url}
|
||||||
>
|
>
|
||||||
{title}
|
{title}
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
import NextLink from "next/link"
|
|
||||||
import { Suspense } from "react"
|
import { Suspense } from "react"
|
||||||
|
|
||||||
import Image from "@/components/Image"
|
|
||||||
import { getIntl } from "@/i18n"
|
|
||||||
import { getLang } from "@/i18n/serverContext"
|
|
||||||
|
|
||||||
import { NavigationMenuListSkeleton } from "./NavigationMenu/NavigationMenuList"
|
import { NavigationMenuListSkeleton } from "./NavigationMenu/NavigationMenuList"
|
||||||
|
import { LogoLink } from "./LogoLink"
|
||||||
import { MobileMenuSkeleton } from "./MobileMenu"
|
import { MobileMenuSkeleton } from "./MobileMenu"
|
||||||
import MobileMenuWrapper from "./MobileMenuWrapper"
|
import MobileMenuWrapper from "./MobileMenuWrapper"
|
||||||
import MyPagesMenuWrapper, {
|
import MyPagesMenuWrapper, {
|
||||||
@@ -19,9 +15,7 @@ export default function MainMenu() {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.mainMenu}>
|
<div className={styles.mainMenu}>
|
||||||
<nav className={styles.nav}>
|
<nav className={styles.nav}>
|
||||||
<Suspense fallback={<Logo alt="..." />}>
|
<LogoLink />
|
||||||
<MainMenuLogo />
|
|
||||||
</Suspense>
|
|
||||||
<div className={styles.menus}>
|
<div className={styles.menus}>
|
||||||
<Suspense fallback={<NavigationMenuListSkeleton />}>
|
<Suspense fallback={<NavigationMenuListSkeleton />}>
|
||||||
<NavigationMenu isMobile={false} />
|
<NavigationMenu isMobile={false} />
|
||||||
@@ -39,26 +33,3 @@ export default function MainMenu() {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function MainMenuLogo() {
|
|
||||||
const intl = await getIntl()
|
|
||||||
|
|
||||||
return <Logo alt={intl.formatMessage({ id: "Back to scandichotels.com" })} />
|
|
||||||
}
|
|
||||||
|
|
||||||
function Logo({ alt }: { alt: string }) {
|
|
||||||
const lang = getLang()
|
|
||||||
|
|
||||||
return (
|
|
||||||
<NextLink className={styles.logoLink} href={`/${lang}`}>
|
|
||||||
<Image
|
|
||||||
alt={alt}
|
|
||||||
className={styles.logo}
|
|
||||||
height={22}
|
|
||||||
src="/_static/img/scandic-logotype.svg"
|
|
||||||
priority
|
|
||||||
width={103}
|
|
||||||
/>
|
|
||||||
</NextLink>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -23,15 +23,6 @@
|
|||||||
gap: var(--Spacing-x2);
|
gap: var(--Spacing-x2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.logoLink {
|
|
||||||
display: inline-flex;
|
|
||||||
width: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.logo {
|
|
||||||
height: 1.375rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 768px) {
|
@media screen and (min-width: 768px) {
|
||||||
.mainMenu {
|
.mainMenu {
|
||||||
padding: var(--Spacing-x2) 0;
|
padding: var(--Spacing-x2) 0;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {
|
|||||||
DropdownTypeEnum,
|
DropdownTypeEnum,
|
||||||
} from "@/types/components/dropdown/dropdown"
|
} from "@/types/components/dropdown/dropdown"
|
||||||
|
|
||||||
const useDropdownStore = create<DropdownState>((set, get) => ({
|
const useDropdownStore = create<DropdownState>((set) => ({
|
||||||
isHamburgerMenuOpen: false,
|
isHamburgerMenuOpen: false,
|
||||||
isMyPagesMobileMenuOpen: false,
|
isMyPagesMobileMenuOpen: false,
|
||||||
isMyPagesMenuOpen: false,
|
isMyPagesMenuOpen: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user