List
A styled list, optionally selectable like a listbox.
Example
<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.
<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>import { List } from '@focsd-dev/react';
export function Example() { return <List onChange={(e) => console.log(e.target)} label="Recent files">…</List>;}<script setup>import '@focsd-dev/components/focsd-list.js';</script>
<template> <focsd-list @change="onChange" label="Recent files">…</focsd-list></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-list.js';
// template<focsd-list (change)="onChange($event)" label="Recent files">…</focsd-list><script> import '@focsd-dev/components/focsd-list.js';</script>
<focsd-list onchange={(e) => console.log(e.target)} label="Recent files">…</focsd-list>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
label | label | string | — |
selectable | selectable | boolean | false |
value | value | string | — |
sortable | sortable | boolean | false |
Events
| Event | Description |
|---|---|
change | Fired when the user commits a change to the value or state. |
Slots
| Slot | Description |
|---|---|
(default) | Default content. |
CSS parts
Style the inside of the component with ::part(), for example focsd-list::part(list).
| Part | Description |
|---|---|
list | The list element. |
Accessibility
- Static:
role="list"andlistitem. - Selectable: a labeled
role="listbox"ofoptions witharia-selected, one tab stop, firingchange.
Keyboard
| Key | Action |
|---|---|
| Arrow Up / Down | Move (selectable) |
| Home / End | First / last item |
| Enter / Space | Select |
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
labelso 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-reorderwithdetail.from,detail.toanddetail.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
selectableandsortableputs 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
| Key | Action |
|---|---|
| Space / Enter (on a handle) | Grab the item, or drop it |
| Arrow Up / Down | Move the grabbed item one place |
| Escape | Put the item back where it was |
| Tab | Drop the item and move on |
| Alt + Arrow Up / Down | Move the focused option one place (selectable and sortable) |
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.