Skip to content

CdsSlideGroup

A slide group lays a set of elements out in a single scrollable line: when the elements do not fit, the strip is paged with arrows. It can also drive a selection through v-model — CdsTabs and CdsTagGroup are built on the slide group.

Storybook GitLab
Test coverage: no tests

This component has no automated tests yet: its behavior is verified manually only.

API in specs
0 / 32 props, events, slots and exposed members with a test
Test cases
0 unit · 0 browser
Code coverage
51.7% lines · 37.2% branches measured in v4.0.0-alpha.13
A11y (axe)
16 recommendations in 11 stories measured in v4.0.0-alpha.11

For a bar of sections take the ready CdsTabs, for picking tags take CdsTagGroup, and to page through slides one by one take CdsSlideView.

Anatomy ​

Arrow buttons sit at the edges of the container, and the strip of elements scrolls between them. The arrows appear only when the strip does not fit into the container, and they page it by the width of the visible area.

Variations ​

Scrolling and arrows ​

By default the arrows appear on a desktop when the elements do not fit into the container; on mobile the strip is scrolled with a finger without arrows. The show-arrows prop changes this behavior: true shows the arrows on overflow and on mobile, desktop and mobile always show them on the matching devices, always always shows them, never never does.

Selecting elements ​

Wrap the elements into CdsSlideGroupItem and the group starts driving the selection: v-model holds the value of the selected element from its value prop. CdsSlideGroupItem itself renders nothing — its slot receives isSelected and toggle, and how to show the selected state is up to you. The mandatory prop forbids clearing the last selection.

The multiple prop allows selecting several elements — v-model becomes an array, and max limits the number of selected ones.

The active element in the center ​

When the selection changes, the strip scrolls to the active element itself — that is the job of scroll-to-active, which is on by default. The center-active prop additionally keeps the active element in the center of the container.

Vertical group ​

The direction="vertical" prop turns the strip into a column — limit its height with max-height on the group itself.

Slots ​

SlotDescription
defaultThe elements of the strip, usually CdsSlideGroupItem
prevYour own content for the "back" button instead of the arrow
nextYour own content for the "forward" button instead of the arrow

All the slots receive the prev, next, select and isSelected methods. The click on the area of an arrow is handled by the group itself, so it is enough to put the visuals only into prev / next. The icons of the default arrows are changed without slots — with the prev-icon and next-icon props.

Guidelines ​

Scenarios ​

Booking an appointment ​

Two slide groups with a selection: the strip of days with center-active keeps the selected date in the center, and the strip of times is more compact — with size="sm" buttons. Both lists use mandatory: a booking always has a selected date and time.

A strip of documents ​

The slide group works without a selection too — as a regular scrollable strip. The cards go straight into the default slot without CdsSlideGroupItem, and the arrows page the strip by the width of the visible area.

A formatting bar ​

A toolbar inside a narrow container: icon buttons with aria-label, multiple allows turning several formats on at once, and the show-arrows="always" arrows page through the tools that did not fit.

API ​

CdsSlideGroup ​

Props

NameTypeDefaultDescription
centerActiveboolean | undefined—Forces the active component to be aligned to the center.
contentClassany—Adds classes to the slide group container
contentStyleany—Adds inline styles to the slide group container
direction"horizontal" | "vertical" | undefined'horizontal'Switches the component between horizontal and vertical layout.
disabledboolean | null | undefinednullDisabled state
mandatoryboolean | "force" | undefined—Requires at least one item to stay selected
maxnumber | undefined—Maximum number of items that can be selected
mobileboolean | null | undefinednullDetermines the display mode of the component: true renders it in mobile mode, false in desktop mode, null makes the mode depend on the current breakpoint.
mobileBreakpointnumber | "xs" | "sm" | "md" | "lg" | "xl" | undefined—Sets the breakpoint at which the component switches to mobile mode. Accepts a number (for example, 600) or the name of a predefined breakpoint (xs, sm, md, lg, xl).
modelValueany—Value of the selected items of the group
multipleboolean | undefined—Allows selecting several items at once
nextIconIconValue | undefined'chevron-right'Icon for the “next” button.
prevIconIconValue | undefined'chevron-left'Icon for the “previous” button.
requiredboolean | "force" | undefined—Requires at least one item to stay selected
scrollToActiveboolean | undefinedtrueWhen true, the container scrolls the active component into view whenever it changes.
selectedClassstring | undefined'cds-slide-group-item--active'CSS class applied in the selected state
showArrowsstring | boolean | undefined—Changes how the arrows are shown. By default the arrows appear on desktop devices when the container overflows and stay hidden on mobile devices. true also shows them on mobile on overflow, desktop always shows them on desktop, mobile always on mobile, always on both, and never disables the arrows.
tagstring | JSXComponent<any> | undefined'div'Custom HTML tag or component to render

Slots

NameTypeDescription
defaultSlideGroupSlotSlot for the CdsSlideGroupItem components
nextSlideGroupSlotSlot for the "next" button.
prevSlideGroupSlotSlot for the "previous" button.

Exposed

NameTypeDescription
focus(location?: "next" | "prev" | "first" | "last" | undefined) => voidFocuses the component
hasNextbooleanReturns true if there are elements after the current index.
hasPrevbooleanReturns true if there are elements before the current index.
scrollOffsetnumberReturns the scroll offset of the element
scrollTo(location: "next" | "prev") => voidScrolls to the element by its index
selectedreadonly string[]Returns the index of the selected element

CdsSlideGroupItem ​

Props

NameTypeDefaultDescription
disabledboolean | null | undefinednullDisabled state
selectedClassstring | undefined—CSS class applied in the selected state
valueany—Value of the component within the group

Events

NameTypeDescription
group:selected[value: { value: boolean; }]Fires when an element is selected inside the group.

Slots

NameTypeDescription
default{ isSelected: boolean; select: (value: boolean) => void; toggle: () => void; selectedClass: false | (string | undefined)[]; }Slot for the content