Navigation

A menu of links; indented items become a submenu.

When to use it

Menus: the site's sections in the header, links in the footer, the side menu of a guide. It can list a folder's pages by itself or the links you write.

When not to

A list of articles (use list-pages) and actions (use buttons).

Accessibility

A navigation landmark; the current page is marked as current. On small screens the header menu folds behind a button that says whether it is open and works with the keyboard; without its script, the menu stays open.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

Where it is used

The starter sites that use it, each at a page that shows it:

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. Each row is a key and its value, in any order.

Field

Key

Kind

Required

Navigation root

root

A link: its text and address

No

Depth

depth

A value from a short list, or a setting

No

Order

order

A value from a short list, or a setting

No

Open submenus (all, or current: only the section of this page)

open

A value from a short list, or a setting

No

Items

items

A list of items

No

Variants

A variant changes how the component looks. Write it in parentheses after the name in the table’s first cell, several separated by commas.

Variant

Write in the first cell

Footer menu

nav (footer)

Side menu of a section

nav (side)

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table:

nav

depth

1

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "nav",
  "variants": [
    "footer"
  ],
  "rows": [
    [
      "depth",
      "1"
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

nav

The component

nav__item

A part of it

nav__link

A part of it

nav__list

A part of it

nav__sublist

A part of it

nav__toggle

A part of it

nav--footer

A variant

nav--side

A variant

nav--enhanced

Added by the component itself: a setting, or what its script does

nav--open

Added by the component itself: a setting, or what its script does

The HTML the example above writes, as the component library builds it in the default theme:

html
<nav class="nav nav--enhanced" aria-label="Main navigation" data-nav>
<button class="nav__toggle" type="button" aria-expanded="false" aria-controls="nav-1">Menu</button>
<ul class="nav__list" id="nav-1">
<li class="nav__item"><a class="nav__link" href="/components/">Components</a>
<ul class="nav__sublist">
<li class="nav__item"><a class="nav__link" href="/components/accordion/">accordion</a></li>
<li class="nav__item"><a class="nav__link" href="/components/breadcrumb/">breadcrumb</a></li>
<li class="nav__item"><a class="nav__link" href="/components/button/">button</a></li>
<li class="nav__item"><a class="nav__link" href="/components/buttons/">buttons</a></li>
<li class="nav__item"><a class="nav__link" href="/components/cards/">cards</a></li>
<li class="nav__item"><a class="nav__link" href="/components/carousel/">carousel</a></li>
<li class="nav__item"><a class="nav__link" href="/components/code/">code</a></li>
<li class="nav__item"><a class="nav__link" href="/components/columns/">columns</a></li>
<li class="nav__item"><a class="nav__link" href="/components/cta/">cta</a></li>
<li class="nav__item"><a class="nav__link" href="/components/dishes/">dishes</a></li>
<li class="nav__item"><a class="nav__link" href="/components/embed/">embed</a></li>
<li class="nav__item"><a class="nav__link" href="/components/facts/">facts</a></li>
<li class="nav__item"><a class="nav__link" href="/components/fragment/">fragment</a></li>
<li class="nav__item"><a class="nav__link" href="/components/gallery/">gallery</a></li>
<li class="nav__item"><a class="nav__link" href="/components/hero/">hero</a></li>
<li class="nav__item"><a class="nav__link" href="/components/image/">image</a></li>
<li class="nav__item"><a class="nav__link" href="/components/language-switcher/">language-switcher</a></li>
<li class="nav__item"><a class="nav__link" href="/components/lead/">lead</a></li>
<li class="nav__item"><a class="nav__link" href="/components/list-pages/">list-pages</a></li>
<li class="nav__item"><a class="nav__link" href="/components/nav/" aria-current="page">nav</a></li>
<li class="nav__item"><a class="nav__link" href="/components/note/">note</a></li>
<li class="nav__item"><a class="nav__link" href="/components/pager/">pager</a></li>
<li class="nav__item"><a class="nav__link" href="/components/products/">products</a></li>
<li class="nav__item"><a class="nav__link" href="/components/profile/">profile</a></li>
<li class="nav__item"><a class="nav__link" href="/components/profiles/">profiles</a></li>
<li class="nav__item"><a class="nav__link" href="/components/quote/">quote</a></li>
<li class="nav__item"><a class="nav__link" href="/components/schedule/">schedule</a></li>
<li class="nav__item"><a class="nav__link" href="/components/search/">search</a></li>
<li class="nav__item"><a class="nav__link" href="/components/separator/">separator</a></li>
<li class="nav__item"><a class="nav__link" href="/components/share/">share</a></li>
<li class="nav__item"><a class="nav__link" href="/components/site-logo/">site-logo</a></li>
<li class="nav__item"><a class="nav__link" href="/components/steps/">steps</a></li>
<li class="nav__item"><a class="nav__link" href="/components/table/">table</a></li>
<li class="nav__item"><a class="nav__link" href="/components/tabs/">tabs</a></li>
<li class="nav__item"><a class="nav__link" href="/components/teaser/">teaser</a></li>
<!-- and more -->

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.nav.label

Main navigation

site.nav.footer

Footer navigation

site.nav.menu

Menu

site.nav.side

Section navigation

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/nav.js
  • src/components/nav/nav.liquid
  • src/components/nav.client.js

It has a browser script, the .client.js file above. Without it the component still shows all its content; the script only adds behaviour.