Principi Base Accessibilité Sistema di design Guidelines Deutsch Français Italiano English I nostri principi di design Soluzioni focalizzate sull’utente Riconoscibilità Inclusione Riduzione Olistico Autoesplicativo Orientamento all’attività Adeguatezza Portale della marca FFS Logo Orologio digitale Diritti di utilizzazione Colori die base Colori addizionali Colori Off Brand Icone Icone dell'orario Pittogrammi Informazioni sull’accessibilità Über diesen Guide Contatti Letture consigliate Product Owner User Research Interaction Design Visual Design Development Content Design Testing What is a design system? Designing Coding FAQ Aiuto Processo Contribution Contatto Introduzione Base Componenti Introduzione Releases Design Tokens Componenti Introduzione Base Informations Introduzione Base Componenti Introduzione Power-Apps Banner pubblicitari digitali SAP IA Design : Base. Icone delle app Questa pagina non è disponibile nella lingua desiderata. Lingue disponibili: Deutsch English Sidebar Info

Was macht die Komponente?

Die Sidebar ist eine vertikale Navigationsleiste, die zur Strukturierung von Inhalten innerhalb einer Anwendung dient. Sie ermöglicht eine schnelle und intuitive Navigation zwischen verschiedenen Bereichen oder Funktionen der Anwendung. Die Sidebar kann Menüpunkte enthalten und bietet Platz für zusätzliche interaktive Elemente wie Suchfelder oder Filter.

Wann soll die Komponente eingesetzt werden?

  • Wenn eine Anwendung eine permanente oder leicht zugängliche Navigation benötigt.
  • Wenn Benutzer:innen schnell zwischen mehreren Hauptbereichen wechseln müssen.
  • Wenn zusätzliche Funktionen oder Filter neben dem Hauptinhalt verfügbar sein sollen.

Regeln

  • Die Sidebar kann mit der Icon-Sidebar kombiniert werden. In diesem Fall soll entweder die Icon-Sidebar oder Sidebar die Farbvariante «Milk» verwenden, damit sich die zwei Komponenten visuell differenzieren lassen.
Icon-Sidebar Sidebar-Title Sidebar-Content Sidebar-Close-Button Sidebar-Container
Anatomie

Anatomie der Komponente


Nummer Typ Beschreibung Optional Hinweis
1 Komponente sbb-sidebar-title Ja
2 Komponente sbb-sidebar-close-button Ja
3 Inhalt Beliebiger Nein
4 Eigenschaft Backdrop Ja Nur im Overlay-Mode sichtbar
5 Komponente sbb-icon-sidebar Ja
6 Komponente sbb-icon-sidebar-button oder sbb-icon-sidebar-link Nein
6a Komponente sbb-icon-sidebar-button oder sbb-icon-sidebar-link Nein Hover State mit Tooltip
6b Komponente sbb-icon-sidebar-button oder sbb-icon-sidebar-link Nein Current State
Demo Default
Milk
Milk End
Over
Nested
Nested Over
Nested End
Two Sidebars
HTML in Zwischenablage kopiert.
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 .