Principles Foundation Accessibility Design System Guidelines Deutsch Français Italiano English Our design principles User-centred Recognisable Inclusive Reduced Holistic Self-explanatory Task-oriented Appropriate SBB Brand portal Logo Digital clock Rights of use Base colors Additional colors Off brand colors Icons Timetable icons Pictograms About accessibility Über diesen Guide Contact Further information Product Owner User Research Interaction Design Visual Design Development Content Design Testing What is a design system? Designing Coding FAQ Help Process Contribution Contact Overview Base Components Overview Releases Design Tokens Components Overview Base Informations Overview Base Components Overview App Icons Power-Apps Digital banner ads SAP Design Guidelines AI Design: Basics Sidebar Info

What does the component do?

The sidebar is a vertical navigation bar that is used to structure content within an application. It enables quick and intuitive navigation between different areas or functions of the application. The sidebar can contain menu items and offers space for additional interactive elements such as search fields or filters.

When should the component be used?

  • When an application requires permanent or easily accessible navigation.
  • When users need to switch quickly between several main areas.
  • When additional functions or filters should be available alongside the main content.

Rules

  • The sidebar can be combined with the icon sidebar. In this case, either the icon sidebar or sidebar should use the ‘milk’ colour variant so that the two components can be visually differentiated.
Icon-Sidebar Sidebar-Title Sidebar-Content Sidebar-Close-Button Sidebar-Container
Anatomy

Anatomy of the component


Number Type Description Optional Info
1 Component sbb-sidebar-title Yes
2 Component sbb-sidebar-close-button Yes
3 Content No
4 Property Backdrop Yes Only visible in overlay mode
5 Component sbb-icon-sidebar Yes
6 Component sbb-icon-sidebar-button or sbb-icon-sidebar-link No
6a Component sbb-icon-sidebar-button or sbb-icon-sidebar-link No Hover state with tooltip
6b Component sbb-icon-sidebar-button or sbb-icon-sidebar-link No Current state
Demo Default
Milk
Milk End
Over
Nested
Nested Over
Nested End
Two Sidebars
Copy HTML to clipboard.
Implementation

The <sbb-sidebar> is a component that can display items on the left or right side of the viewport.
Every slotted content will be displayed, but it's designed to be used for navigation.

The sidebar components are designed to add side content to a fullscreen app.
To set up a sidebar we use three components: <sbb-sidebar-container> which acts as a structural container for
our content and sidebar, <sbb-sidebar-content> which represents the main content,
and <sbb-sidebar> which represents the added side content.

Per <sbb-sidebar-container> it's allowed to place one <sbb-sidebar> with position="start"
and one <sbb-sidebar> with position="end". More than one sidebar of the same position value is not allowed.

<sbb-sidebar-container>
  <sbb-sidebar role="navigation">
    <sbb-sidebar-title>Sidebar Title</sbb-sidebar-title>
    <sbb-sidebar-close-button></sbb-sidebar-close-button>
    <sbb-link-list>
      <sbb-block-link href="#">Link 1</sbb-block-link>
      <sbb-block-link href="#" class="sbb-active" accessibility-current="page">
        Link 2
      </sbb-block-link>
    </sbb-link-list>
  </sbb-sidebar>
  <sbb-sidebar-content role="main">
    <p style="padding: var(--sbb-spacing-fixed-4x); margin: 0">
      In the enchanting world of fantasy, unicorns are legendary creatures known for their grace,
      purity, and magical abilities. These mystical beings have inspired countless tales of bravery
      and wonder. Here, we delve into some captivating unicorn success stories that continue to
      enchant and inspire, each with a touch of public transport magic.
    </p>
  </sbb-sidebar-content>
</sbb-sidebar-container>

Opening and closing a sidebar

A <sbb-sidebar> can be opened or closed using the open(), close() and toggle() methods.

The opened state can also be set via the opened property.

Listening to the open and close events allows to react after transitions have been executed.
If for a certain reason the opening or closing should be prevented,
it's possible to call preventDefault() on the beforeopen or beforeclose events.

It is strongly recommended to use a button to toggle the sidebar.
Even with mode="side" and an opened sidebar at larger sizes, the sidebar will collapse if there is not enough space.
In this case a toggle button is strongly recommended, otherwise the user will not be able to open the sidebar.
Ideally the button can be placed in the <sbb-header>.

Close button

By slotting a <sbb-sidebar-close-button> into the <sbb-sidebar>, a close button will be shown.

<sbb-sidebar role="navigation">
  <sbb-sidebar-close-button></sbb-sidebar-close-button>
  Sidebar Content
</sbb-sidebar>

Title

We recommend to give the sidebar a title by using the <sbb-sidebar-title> element.

<sbb-sidebar role="navigation">
  <sbb-sidebar-title>Title</sbb-sidebar-title>
</sbb-sidebar>

Mode

The <sbb-sidebar> can be rendered in one of two different ways based on the mode property.

Mode Description
side Sidebar appears side-by-side with the main content, shrinking the main content's width to make space for the sidebar.
over Sidebar floats over the primary content, which is covered by a backdrop

If no mode is specified, side is used by default. The over sidebar mode shows a backdrop,
while the side mode does not.

If there is not enough space available and the mode is side, the sidebar collapses and automatically
changes to a forced over mode (the mode property itself will not change).
Whenever there is enough space available, the <sbb-sidebar> changes back to mode side.

At maximum, one <sbb-sidebar> with mode="over" should be opened simultaneously on a page.

<sbb-sidebar mode="over" role="navigation"></sbb-sidebar>

Color

Per default, the <sbb-sidebar> receives a white background color. As alternative,
it's possible to set the color property to milk.
If using the <sbb-sidebar> along with a <sbb-icon-sidebar>, it's recommended to alternate
the background colors (white / milk) for a clear visual distinction.

<sbb-sidebar color="milk" role="navigation"></sbb-sidebar>

Position

An <sbb-sidebar> can be positioned via position property and its values start or end.
To display the sidebar on the right side, place the <sbb-sidebar>
after the <sbb-sidebar-content> in the DOM which guarantees a logical order for focusing.

<sbb-sidebar-container>
  <sbb-sidebar-content role="main">Content</sbb-sidebar-content>
  <sbb-sidebar position="end" role="navigation">Sidebar Content</sbb-sidebar>
</sbb-sidebar-container>

Size

The <sbb-sidebar> has a default width. The width can
be explicitly set via CSS:

sbb-sidebar {
  width: 200px;
}

Accessibility

If the sidebar is on mode="over", the sidebar acts like an overlay element with an activated focus trap.

Roles

The <sbb-sidebar> and <sbb-sidebar-content> should each be given an appropriate role attribute
depending on the context in which they are used.

For example, a <sbb-sidebar> that contains links
to other pages might be marked role="navigation", whereas one that contains a table of
contents about might be marked as role="directory". If there is no more specific role that
describes your sidebar, role="region" is recommended.

Similarly, the <sbb-sidebar-content> should be given a role based on what it contains. If it
represents the primary content of the page, it may make sense to mark it role="main". If no more
specific role makes sense, role="region" is again a good fallback.

Active / Current State

Whenever an action item has an active state, it's recommended to set aria-current="page"
respectively accessibility-current="page" for link elements.
For link elements, the class sbb-active can be used to visually display an active state.

<sbb-sidebar role="navigation">
  <sbb-link-list>
    <sbb-block-link>Link 1</sbb-block-link>
    <sbb-block-link class="sbb-active" accessibility-current="page">Link 2</sbb-block-link>
  </sbb-link-list>
</sbb-sidebar

Trigger Button

If a button should trigger the opening or closing, certain
accessibility information on the trigger button should be set.

  • aria-controls="id of the sidebar" (id should be linked to the sidebar)
  • aria-expanded="true" or aria-expanded="false" (should be updated to the opened state of the sidebar)
  • aria-label (Describes the toggle action)
<sbb-header expanded scroll-origin="content" size="s">
  <sbb-header-button
    id="toggle-button"
    icon-name="arrows-right-left-small"
    aria-controls="sidebar"
    aria-expanded="true"
    @click="${() => document.querySelector('#sidebar')?.toggle() }"
  >
    Toggle sidebar
  </sbb-header-button>
</sbb-header>
<sbb-sidebar-container>
  <sbb-sidebar
    id="sidebar"
    role="navigation"
    @open="${() => document.querySelector('#toggle-button')?.setAttribute('aria-expanded', 'true') }"
    @close="${() => document.querySelector('#toggle-button')?.setAttribute('aria-expanded', 'false') }"
  >
    <sbb-link-list>
      <sbb-block-link>Link 1</sbb-block-link>
      <sbb-block-link class="sbb-active" accessibility-current="page">Link 2</sbb-block-link>
    </sbb-link-list>
  </sbb-sidebar>
  <sbb-sidebar-content role="main" id="content">Content</sbb-sidebar-content>
</sbb-sidebar-container>

Controlling initial focus

The first element with the attribute sbb-focus-initial will receive focus on opening.
If the attribute is not used, the first focusable element receives focus (recommended).

<sbb-sidebar-container>
  <sbb-sidebar role="navigation">
    <sbb-link-list>
      <sbb-block-link>Link 1</sbb-block-link>
      <sbb-block-link sbb-focus-initial>Link 2</sbb-block-link>
    </sbb-link-list>
  </sbb-sidebar>
  <sbb-sidebar-content role="main">Content</sbb-sidebar-content>
</sbb-sidebar-container>

Combine with <sbb-icon-sidebar>

It's possible the combine the <sbb-sidebar> with the <sbb-icon-sidebar> as following:

<sbb-icon-sidebar-container>
  <sbb-icon-sidebar>Icon sidebar content</sbb-icon-sidebar>
  <sbb-icon-sidebar-content>
    <sbb-sidebar-container>
      <sbb-sidebar role="navigation">Sidebar content</sbb-sidebar>
      <sbb-sidebar-content role="main">Content</sbb-sidebar-content>
    </sbb-sidebar-container>
  </sbb-icon-sidebar-content>
</sbb-icon-sidebar-container>

Use with sbb-header

Check sbb-sidebar-container on how to
position and connect the <sbb-header> with the sidebar.

Properties

Name Attribute Privacy Type Default Description
animationComplete - public Promise<void> Returns a promise which completes whenever an animation ends. When a new animation starts, a new Promise is returned.
color color public 'white' | 'milk' 'white' Background color of the sidebar. Either white or milk.
container - public SbbSidebarContainerElement | null null Returns the SbbSidebarContainerElement where this sidebar is contained.
focusOnOpen focus-on-open public boolean false Whether the sidebar should focus the first focusable element automatically when opened. Defaults to false in when mode is set to side, otherwise defaults to true. If explicitly enabled, focus will be moved into the sidebar in side mode as well.
isAnimating - public boolean false Whether the component is currently animating.
isOpen - public boolean Whether the element is open.
mode mode public 'side' | 'over' 'side' Mode of the sidebar; one of 'side' or 'over'.
opened opened public boolean false Whether the sidebar is opened or closed. Can be used to initially set the opened state, where the animation will be skipped.
position position public 'start' | 'end' 'start' The side that the sidebar is attached to.

Methods

Name Privacy Description Parameters Return Inherited From
close public Closes the sidebar. void SbbOpenCloseBaseElement
escapeStrategy public The method which is called on escape key press. Defaults to calling close() void SbbOpenCloseBaseElement
open public Opens the sidebar. void SbbOpenCloseBaseElement
toggle public Toggles the sidebar visibility. void

Events

Name Type Description Inherited From
beforeclose Event Emits whenever the component begins the closing transition. Can be canceled. SbbOpenCloseBaseElement
beforeopen Event Emits whenever the component starts the opening transition. Can be canceled. SbbOpenCloseBaseElement
close Event Emits whenever the component is closed. SbbOpenCloseBaseElement
open Event Emits whenever the component is opened. SbbOpenCloseBaseElement

Slots

Name Description
Use the unnamed slot to slot any content into the sidebar.
title Use the title slot to add an .