--- layout: layouts/page.njk title: Sidebar description: A composable, themeable and customizable sidebar component. toc: - label: Usage id: usage children: - label: HTML + JavaScript id: usage-html-js children: - label: "Step 1: Include the JavaScript files" id: usage-html-js-1 - label: "Step 2: Add your sidebar HTML" id: usage-html-js-2 - label: HTML structure id: usage-html-js-3 - label: JavaScript events id: usage-html-js-4 - label: Jinja and Nunjucks id: usage-macro --- {% from "macros/code_block.njk" import code_block %} {% from "sidebar.njk" import sidebar %}
You can either include the JavaScript file for all the components, or just the one for this component by adding this to the <head> of your page:
<aside class="sidebar" aria-hidden="false">aria-hidden="true": controls the default state of the sidebar (hidden or visible).data-side="left": specifies the side of the sidebar (left or right, defaults to left).<nav>The navigation element that contains the sidebar's content. It can have the following attributes:
id="{BUTTON_ID}": linked to by the aria-labelledby attribute of the listbox.aria-haspopup="menu": indicates that the button opens a menu.aria-controls="{ MENU_ID }": points to the menu's id.aria-expanded="false": tracks the popover's state.<header> Optional<section><div role="group">aria-labelledby attribute to link to a heading.<span role="heading">id attribute if you use the aria-labelledby attribute on the group.<ul><li><a>data-keep-mobile-sidebar-open attribute is present.<button>data-keep-mobile-sidebar-open attribute is present.<details><summary><ul><footer> Optional<main><button type="button" onclick="document.dispatchEvent(new CustomEvent('basecoat:sidebar'))"><aside class="sidebar" id="{SIDEBAR_ID}">) and refer to them in the event detail (i.e. document.dispatchEvent(new CustomEvent('basecoat:sidebar', { detail: { id: '{SIDEBAR_ID}' } }));).basecoat:initializedbasecoat:initialized event on itself.basecoat:sidebarSidebars listen for this event on document to open, close or toggle themselves. By default, the event will toggle the sidebar, but can be used to open or close if you add an action to the detail. Additionally, if you have multiple sidebars on the page, you can target a specific sidebar by adding its id to the detail:
You can use the sidebar() Nunjucks or Jinja macro for this component.