Dock
A compact row of icons in a raised container for switching between views or categories, one at a time. Labels show as tooltips, or under the icons.
Example
<div class="stack"> <focsd-dock label="Mail folders" name="folder" value="starred" id="dock-demo"> <focsd-dock-item value="starred" icon="star">Starred</focsd-dock-item> <focsd-dock-item value="search" icon="search">Search</focsd-dock-item> <focsd-dock-item value="schedule" icon="calendar">Schedule</focsd-dock-item> <focsd-dock-item value="drafts" icon="edit">Drafts</focsd-dock-item> </focsd-dock> <output id="dock-demo-out" for="dock-demo" aria-live="polite">Showing starred</output></div>
<script type="module">const dock = document.getElementById('dock-demo');const out = document.getElementById('dock-demo-out');
dock.addEventListener('change', () => { out.textContent = 'Showing ' + dock.value;});</script>Labels under the icons, your own icons and sizes
label-display="shown" puts each label under its icon. Put any SVG or focsd-icon in the icon slot. size takes s, m or l.
<div class="stack"> <focsd-dock label="Layout" size="s" value="grid" label-display="shown"> <focsd-dock-item value="grid"> <svg slot="icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"> <rect x="3" y="3" width="7" height="7" rx="1" /> <rect x="14" y="3" width="7" height="7" rx="1" /> <rect x="3" y="14" width="7" height="7" rx="1" /> <rect x="14" y="14" width="7" height="7" rx="1" /> </svg> Grid </focsd-dock-item> <focsd-dock-item value="list" icon="menu">List</focsd-dock-item> </focsd-dock> <focsd-dock label="Text alignment" size="l" value="left"> <focsd-dock-item value="left" icon="arrow-left">Align left</focsd-dock-item> <focsd-dock-item value="right" icon="arrow-right">Align right</focsd-dock-item> </focsd-dock></div>Usage
Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-dock.js';</script>
<focsd-dock label="Mail folders" name="folder" value="starred">…</focsd-dock>import { Dock } from '@focsd-dev/react';
export function Example() { return <Dock onChange={(e) => console.log(e.target)} label="Mail folders" name="folder" value="starred">…</Dock>;}<script setup>import '@focsd-dev/components/focsd-dock.js';</script>
<template> <focsd-dock @change="onChange" label="Mail folders" name="folder" value="starred">…</focsd-dock></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-dock.js';
// template<focsd-dock (change)="onChange($event)" label="Mail folders" name="folder" value="starred">…</focsd-dock><script> import '@focsd-dev/components/focsd-dock.js';</script>
<focsd-dock onchange={(e) => console.log(e.target)} label="Mail folders" name="folder" value="starred">…</focsd-dock>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label-display | labelDisplay | 'shown' | 'hidden' | hidden |
size | size | 's' | 'm' | 'l' | m |
name | name | string | — |
disabled | disabled | boolean | false |
required | required | boolean | false |
readonly | readOnly | boolean | false |
aria-label | hostAriaLabel | string | null | null |
aria-description | hostAriaDescription | string | null | null |
aria-labelledby | hostAriaLabelledBy | string | null | null |
aria-describedby | hostAriaDescribedBy | string | null | null |
label | label | string | — |
value | value | string | — |
Methods
| Method | Description |
|---|---|
describedByIds() | IDs to add to the inner control's aria-describedby: the hint, then the shown message. |
checkValidity() | True when the value is valid; otherwise fires invalid and returns false, like native. |
reportValidity() | Like checkValidity(), and also shows the browser's validation message when invalid. |
setCustomValidity(message) | Set (non-empty) or clear (empty string) a custom validation error, like native controls. |
setValidityState(flags, message, anchor) | For subclasses: set the validity flags and message. anchor is the element the browser points its message at. |
validate() | Show (or clear) the error from the control's own checks: required, type, pattern, min,
max and the like. Uses error-message, else the browser's localized message. An error the
author set (a server error, say) is left as it is. |
clearValidation() | Clear the error and warning that validate() and warning-pattern showed (a form reset does). |
emitValue(commit) | For subclasses: fire the value events, as a native control does on a user edit: input
(bubbles, composed), then with commit also change (bubbles, stays in its tree). |
idrefText(ids) | For subclasses: the text of the elements an ID reference list names, resolved in the host's tree (ID references cannot cross a shadow root), joined by spaces. |
Events
| Event | Description |
|---|---|
input | Fired on every user edit of the value. |
change | Fired when the user commits a change to the value or state. |
Slots
| Slot | Description |
|---|---|
(default) | The focsd-dock-item elements. |
CSS parts
Style the inside of the component with ::part(), for example focsd-dock::part(group).
| Part | Description |
|---|---|
group | The group element (role=radiogroup). |
item | Set on every item element. |
item-selected | Set on the selected item element. |
label | The label element. |
segment | Set on every segment element. |
segment-selected | Set on the selected segment element. |
layout | The wrapper around the label and the body. |
body | The group and the messages. |
hint | The hint text. |
message | The shown message (also error, warning or success). |
message-icon | The icon in the message. |
announcer | The hidden region that announces message changes. |
Accessibility
- A radio group named by
label(default "Views"), with each item a radio named by its text. Screen readers say "Search, radio button, 2 of 4". - Each label shows as a tip on hover and on keyboard focus (Escape hides it), so sighted people can learn what an icon means. Set
label-display="shown"to show the labels under the icons instead. - The dock is an opaque raised surface with an edge and a shadow, so its icons stay readable over any content behind it.
--focsd-dock-background,--focsd-dock-border-color,--focsd-dock-shadowand--focsd-dock-radiusrestyle it. - Selection follows focus: one arrow press moves and chooses. Use it when the choice shows at once, such as a filter or a view.
- The selected item has a filled surface, full-strength text and a bar under it, so color is never the only cue. In forced colors it takes the system selected-item colors.
- Every item is as tall as the density's controls (32, 36 or 44 px), so the dock lines up with buttons and fields beside it, and never under the 24 px target size.
- Not for links between pages: use
focsd-bottom-navorfocsd-nav-menu, which are real links in a navigation landmark.
Keyboard
| Key | Action |
|---|---|
| Arrow keys | Move to the next or previous item and select it (Left and Right swap in right-to-left text) |
| Home / End | First / last item |
| Tab | Move into the dock, then out of it |
Labels under the icons, your own icons and sizes
- The icon is decoration and hidden from assistive technology; the label always names the item, shown or not.
- Show the labels when the icons are not ones everyone knows: visible labels are easier for everyone, and on touch screens there is no hover.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.