Skip to content
Focsd homeFocsd homeFocsd
Forms

List

A styled list, optionally selectable like a listbox.

  • Tag: focsd-list
  • Pattern: List / listbox (selectable)
  • Category: Display

Example

report-q3.pdf roadmap.key Amara Okafor Lukas Brandt Priya Raman (away) Tomás Herrera
HTML
<div class="stack">
<focsd-list label="Recent files">
<focsd-list-item>report-q3.pdf</focsd-list-item>
<focsd-list-item>roadmap.key</focsd-list-item>
</focsd-list>
<focsd-list label="Assignee" selectable value="amara">
<focsd-list-item value="amara">Amara Okafor</focsd-list-item>
<focsd-list-item value="lukas">Lukas Brandt</focsd-list-item>
<focsd-list-item value="priya" disabled>Priya Raman (away)</focsd-list-item>
<focsd-list-item value="tomas">Tomás Herrera</focsd-list-item>
</focsd-list>
</div>

Sortable

Reorder by keyboard with the handle, or drag it.

Write release notes Design review Run the test suite Tag the release Announce it
HTML
<focsd-list label="Release checklist" sortable>
<focsd-list-item>Write release notes</focsd-list-item>
<focsd-list-item>Design review</focsd-list-item>
<focsd-list-item>Run the test suite</focsd-list-item>
<focsd-list-item>Tag the release</focsd-list-item>
<focsd-list-item>Announce it</focsd-list-item>
</focsd-list>

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-list.js';
</script>
<focsd-list label="Recent files">…</focsd-list>

API

Attributes

AttributePropertyTypeDefault
labellabelstring—
selectableselectablebooleanfalse
valuevaluestring—
sortablesortablebooleanfalse

Events

EventDescription
changeFired when the user commits a change to the value or state.

Slots

SlotDescription
(default)Default content.

CSS parts

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

PartDescription
listThe list element.

Accessibility

  • Static: role="list" and listitem.
  • Selectable: a labeled role="listbox" of options with aria-selected, one tab stop, firing change.

Keyboard

KeyAction
Arrow Up / DownMove (selectable)
Home / EndFirst / last item
Enter / SpaceSelect

Sortable

  • Each item has a "Reorder {item}" button before its content. Grabbing, each move, the drop and a cancel are announced politely ("Grabbed Design review, position 2 of 5", "Moved to position 3 of 5", "Dropped at position 3"). When an item holds other controls, such as a menu button, or its text changes after it is shown, set its label so the handle and announcements use that name and not all of its text.
  • The handle keeps focus while the item moves. A click elsewhere or focus leaving the list puts a grabbed item back.
  • Dragging the handle with a mouse or a finger lifts the item, shows a dashed placeholder where it will land, and scrolls a scrolling container near its edges.
  • The list fires a cancelable focsd-reorder with detail.from, detail.to and detail.item; cancel it to put the item back. Otherwise the list moves the item element itself.
  • A disabled item cannot be moved: its handle is disabled.
  • A list that is both selectable and sortable puts no button inside its options (an option may not hold one). The handle is for a mouse or a finger only and is hidden from screen readers; Alt + Arrow Up or Down moves the focused option one place and announces "Moved to position 2 of 5".

Keyboard

KeyAction
Space / Enter (on a handle)Grab the item, or drop it
Arrow Up / DownMove the grabbed item one place
EscapePut the item back where it was
TabDrop the item and move on
Alt + Arrow Up / DownMove the focused option one place (selectable and sortable)