Skip to content
Focsd homeFocsd homeFocsd
Forms

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.

  • Tag: focsd-dock
  • Pattern: Radio group (selection follows focus)
  • Category: Actions

Example

Starred Search Schedule Drafts Showing starred
HTML
<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.

Grid List Align left Align right
HTML
<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>

API

Attributes

AttributePropertyTypeDefault
label-displaylabelDisplay'shown' | 'hidden'hidden
sizesize's' | 'm' | 'l'm
namenamestring—
disableddisabledbooleanfalse
requiredrequiredbooleanfalse
readonlyreadOnlybooleanfalse
aria-labelhostAriaLabelstring | nullnull
aria-descriptionhostAriaDescriptionstring | nullnull
aria-labelledbyhostAriaLabelledBystring | nullnull
aria-describedbyhostAriaDescribedBystring | nullnull
labellabelstring—
valuevaluestring—

Methods

MethodDescription
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

EventDescription
inputFired on every user edit of the value.
changeFired when the user commits a change to the value or state.

Slots

SlotDescription
(default)The focsd-dock-item elements.

CSS parts

Style the inside of the component with ::part(), for example focsd-dock::part(group).

PartDescription
groupThe group element (role=radiogroup).
itemSet on every item element.
item-selectedSet on the selected item element.
labelThe label element.
segmentSet on every segment element.
segment-selectedSet on the selected segment element.
layoutThe wrapper around the label and the body.
bodyThe group and the messages.
hintThe hint text.
messageThe shown message (also error, warning or success).
message-iconThe icon in the message.
announcerThe 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-shadow and --focsd-dock-radius restyle 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-nav or focsd-nav-menu, which are real links in a navigation landmark.

Keyboard

KeyAction
Arrow keysMove to the next or previous item and select it (Left and Right swap in right-to-left text)
Home / EndFirst / last item
TabMove 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.