carousel

A carousel allows multiple pieces of featured content to occupy an allocated amount of space.

About Carousel

A Carousel can accept a maximum number of 5 panels where only 1 panel is visible at a time.

Accessibility

A Carousel is built using a tabbed UI specification and requires the following to meet accessibility requirements:

  • The tab list, which should have role="tablist"
  • The tabs in that list, which should each be an <a role="tab"> anchor wrapped in a <li role="presentation"> list item
  • The tab panels, which display each tab’s content and should each have role="tabpanel"

Markup

  • Selected tab’s anchor has aria-selected="true", all other tabs’ anchors have aria-selected="false"
  • Selected tab’s anchor has tabindex="0", all other tabs have tabindex="-1"
  • Each tab’s anchor has an aria-controls attribute whose value is the id of the associated <div role="tabpanel">
  • Each tab panel has an aria-labelledby attribute whose value is the id of its associated <a role="tab">
  • Each tab panel has an aria-hidden attribute whose value is toggled based on which panel is visible
  • When the Carousel is set to auto-play, the HTML for the pause button is required to precede the HTML of the tab set

Keyboard Interactions

  • Arrow keys, when focus is on selected tab, cycle selection to the next or previous tab
  • Tab key, when focus is before the tab list, moves focus to the selected tab panel
  • Tab key, when focus is on selected tabpanel, moves focus into the selected tabpanel's associated tab or to the next focusable element on the page if that panel has no focusable elements
  • Shift+Tab keys, when focus is on first element in a tab panel, move focus focus entirely from tabset

Base

Navigating between panels

You are able to navigate between panels but interacting with the slds-carousel__indicator elements that sit below the panel.

Panel 1 active

Panel 2 active

<div class="slds-carousel">
  <div class="slds-carousel__stage">
    <div class="slds-carousel__panels" style="transform:translateX(-100%)">

Accessibility

A panel becomes visible by toggling the aria-hidden attribute from false to true on the slds-carousel__panel element. When a panel becomes active, the `tabindex` of the other non-visible panels should be set to -1 while the active panel remains at 0.

When a panel becomes active, apply an inline style to slds-carousel__panel to move the panels left to right. We do this by updating the location of the panel on its Y axis using transforms. The first panel should be transform: translateX(0%) but when any preceding panel becomes active it can be subtracted by 100%, moving 100% of each panel to the left. For example, panel 1 would be visible at transform: translateX(0%), while panel 3 would be visible at transform: translateX(-200%).

When making the slds-carousel__panel active, the indicator should be updated with the slds-is-active class. This provides visual feedback showing which carousel panel is active.

Auto-play

If the Carousel is set to auto-play, a pause button is required to be first in the HTML before the tab set.

Accessibility

When that pause button is interacted with, the aria-pressed role needs to be toggled to true.

<div class="slds-carousel">
  <div class="slds-carousel__stage">
    <span class="slds-carousel__autoplay">