Olddevs UI4.14.0
ContentEditableList

Overview

Approve the estimate
Pay for hostingOverdue
Send contract amendments
Compile the quarterly budget

Order: 1, 2, 3, 4

When to use

  • A list that a person both edits and extends without leaving it: tasks, a checklist, scenario items.
  • The order matters and is set by a person, not computed.

When not to use

  • For only the order, use SortableList: it is simpler, and its row does nothing extra.
  • If the order is computed from a column value, use Table or DataTable (ADR-0023).
  • For nesting, use TreeView.
  • Hundreds of rows: virtualization and dragging together are not verified in the kit (ADR-0028).

Minimal example

import { EditableList } from "@olddevs/ui";

const [items, setItems] = useState([
  { id: "1", value: "Approve the estimate" },
  { id: "2", value: "Pay for hosting" },
]);

<EditableList
  items={items}
  aria-label="Tasks"
  editLabel={(item) => `Edit "${item.value}"`}
  onReorder={(ids) => setItems(ids.map((id) => items.find((i) => i.id === id)!))}
  onValueChange={(id, value) =>
    setItems(items.map((item) => (item.id === id ? { ...item, value } : item)))
  }
  add={{
    label: "New task",
    placeholder: "What needs to be done?",
    onAdd: (value) => setItems([...items, { id: crypto.randomUUID(), value }]),
  }}
/>;

Props

PropDefaultPurpose
items—Rows: id, value, textValue, disabled.
onReorder—The whole new order — a list of identifiers.
onValueChange—Confirms an edit. Called only when the value changed.
editLabel—The accessible name of the edit field. Required, checked by the compiler.
aria-label—Required. Without a name, a screen reader announces just "list".
add—The add row: label, placeholder, onAdd, pending, leading. pending announces the busy state via aria-busy and does not disable the field; leading sets leading columns, see below.
leading—A slot to the left of the name: a checkbox, an avatar.
trailing—A slot on the right: a status badge, row action buttons.
onRowAction—A click on the row and Space on it. The component does not interpret them.
divided—A hairline between rows.
emptyText—What to show when the list is empty.

Why this is a separate component and not a SortableList with a field inside

The analysis is in ADR-0045.

A SortableList row is a GridListItem, and the keyboard belongs to it: arrow keys, Enter, Space, typeahead by first letters. A field inside the row takes the same keys for itself. The contract must have a single owner, and composition cannot give you one.

The second reason is the add row: it is not a collection item: it has no key and no place in the order. Moving focus into it from the last row and back is behavior that, under composition, is left without an owner.

Accessibility

  • The list is react-aria's GridList. It provides localized move announcements itself; the component has no live region of its own.
  • A row with an empty value gets its name from a placeholder label: react-aria logs a console warning for an empty textValue, and such a row cannot be reached by typing first letters.
  • The component does not announce the appearance of an added row — the row comes from the collection as a prop, and the announcement is left to the consumer.

Anti-patterns

  • Storing the order or the values inside the component.
  • Opening editing with a single click: then the row has nothing left to open details with.
  • Hiding the drag handle "to look cleaner": without it the list is inaccessible from the keyboard.
  • Showing domain state through the component itself — it lives in the slots.
  • Source: src/components/content/EditableList.tsx
  • Decision: ADR-0045
  • Tests: tests/editable-list.test.tsx; browser — tests-visual/interactions.spec.ts (keyboard, focus and the row exit)
  • Showcase: src/components/content/EditableList.stories.tsx

TypeScript types

EditableListProps

Prop

Type

SortableListProps

Prop

Type

On this page