Local Submenu

Questions? Ask in Slack #vcc-ui

@volvo-cars/react-local-submenu

@volvo-cars/react-local-submenu@volvo-cars/react-local-submenu@volvo-cars/react-local-submenu

A secondary navigation menu, typically displayed under the global navigation. It takes any number of links, shown horizontally on large breakpoints and transforms into a dropdown on small and medium breakpoints.

Installation

$ yarn add @volvo-cars/react-local-submenu

💡 This package includes Typescript definitions

📝 This package has built-in translations

LocalSubmenu sticks to the top of the page and follows the user when scrolling. When integrating with the global navigation, the global navigation is expected to stay in place (relative) while the LocalSubmenu sticks.

An example integration with the global navigation can be found in the kitchen-sink example.

Horizontal Navigation

LocalSubmenu behaves as a horizontal navigation on large breakpoints rendering all links in order and scrolls horizontally when links overflow the current viewport width. The current page is highlighted with an active prop on a LocalSubmenuLink.

Dropdown Navigation

LocalSubmenu behaves as a dropdown on small and medium breakpoints, highlighting the current page with a header prop and active prop on the current page LocalSubmenuLink.

🔒 Locked viewport @480px

Accessibility

The LocalSubmenu component is built with accessibility in mind following WAI:ARIA best practices:

  • The LocalSubmenu component is contained within a navigation landmark region.
  • The active element of the current page has aria-current set to page.

The LocalSubmenu component ships with built-in translations for aria-label when toggling the dropdown on small and medium breakpoints if used in conjunction with the Shared translations library.

Tracking

This component integrates with @volvo-cars/tracking, allowing us to dispatch tracking events to GTM. Each LocalSubmenuLink will send an interaction event with click eventAction when trackEventLabel prop is provided.

Clicking on "Our heritage" would send the following event for example

{
"eventCategory": "local submenu",
"eventAction": "click",
"eventLabel": "our heritage | /our-heritage | 1",
"event": "interaction"
}

API

Props - LocalSubmenu

NameDescriptionTypeDefault Value
childrenA single or an array of ReactNodes of type LocalSubmenuLinkReact.ReactNode | React.ReactNode[]n/a
headerHeader to be shown on mobile breakpointsstringn/a
onChangeonChange called when mobile dropdown is toggled((isOpen: boolean) => void)n/a
zIndexstring | numbercalc(var(--sitenav-z-index-min, 990) - 1)

Props - LocalSubmenuLink

NameDescriptionTypeDefault Value
activeHighlights link when truebooleanfalse
aria-labelAn optional aria-label to add to the linkstringn/a
childrenLink textstringn/a
hrefThe URL that the link points tostringn/a
targetAnchor targetstring_self
trackEventLabeleventLabel to dispatch with the dataLayer event, event will not be dispatched if this is not providedstring``
2024 © Volvo Car Corporation