Canvas Design System
Main Site Tokens

Link Switch

Two to four links to versions of the same page, one of them current: 90 | 60, In person | Remote. Each choice is a URL, so it can be shared, bookmarked and printed.

When to Use

Use when: The reader picks which version of this page to see and the choice belongs in the URL, such as a recipe's length or setting. It needs no JavaScript.
Don't use when: Panels switch in place without a reload (Tabs), a setting saves (Toggle), or a list narrows (Filter Bar).

Variants

With a visible label

This one is live: choosing an option reloads this page with ?length= set. The current option is aria-current="true".

<?= ws_link_switch([
    ['label' => '90 min', 'href' => '?code=sprint-retro&length=90', 'current' => true],
    ['label' => '60 min', 'href' => '?code=sprint-retro&length=60'],
], ['label' => 'Length', 'showLabel' => true]) ?>

Without a visible label

When the page already says what is being chosen, label still names the list for screen readers.

<?= ws_link_switch([
    ['label' => 'In person', 'href' => '?mode=in-person', 'current' => true],
    ['label' => 'Remote', 'href' => '?mode=remote'],
], ['label' => 'Setting']) ?>

Options

OptionTypeDefaultPurpose
$itemsarrayrequiredEach option: label, href, current
labelstringrequiredWhat is being switched; names the list
showLabelboolfalseShow the label as text before the options
idstring''Element ID; the visible label's id is {id}-label
classstring''Additional CSS classes
attrsarray[]Extra HTML attributes

Accessibility

ConcernBehavior
SemanticsA list of links, named by the visible label (aria-labelledby) or by aria-label. Not a tablist: choosing an option loads a page.
Currentaria-current="true" on the current option, so it is announced as current, not only shown. On screen it is a 2px --brand ring, 3.82:1 against the white of the other options, with semibold --brand-ink text. In high-contrast mode it fills with Highlight, since every border there repaints alike.
Target sizeEach option is at least 44px tall.
FocusThe platform --focus-ring, drawn outside the pill at --focus-ring-offset.

Tokens

TokenUsed for
--brand, --brand-tint, --brand-inkThe current option: its ring, fill and text
--gray-300, --bg-surface, --color-ink-secondaryThe other options: outline, fill and text
--brand-lineAn option's outline on hover, over --brand-tint
--radius-fullThe pill shape
--font-body, --text-smallThe label and options
--focus-ring, --focus-ring-offsetKeyboard focus

CSS Classes

ClassPurpose
.ws-link-switchThe label and the options
.ws-link-switch__labelThe visible label
.ws-link-switch__optionsThe row of options
.ws-link-switch__option / .is-currentOne option, and the current one

Files

FilePurpose
includes/components/helpers.phpws_link_switch()
includes/components/link-switch.phpTemplate
includes/components/components.cssStyles (.ws-link-switch rules)