Skip to content

CellEditor

One value that can be changed in place, outside a table: in a list, a card or a page of details. The DataTable uses the same behaviour in its cells.

import { CellEditor } from '@sypnia/ui/react'

On this page
  1. Details of a product
  2. When to use it
  3. For everyone
  4. Props

Details of a product

Try a price below zero: the server refuses it.

Name
Price
Category
SKU
Created
Code
import { CellEditor, KeyValue } from '@sypnia/ui/react';

// Press a value to change it. Enter saves, Escape puts the old value back. A price below zero is refused by the
// server: the old value comes back and the reason is said in words.
const save = (v: string) => new Promise<void>((ok, fail) => setTimeout(() => (Number(v) < 0 ? fail(new Error('A price cannot be below zero.')) : ok()), 700));
export default function Prices() {
  return (
    <KeyValue items={[
      ['Name', <CellEditor key="n" label="Name" value="Sourdough loaf" onCommit={save} />],
      ['Price', <CellEditor key="p" label="Price" editor="number" value={6.5} onCommit={save} render={(v) => `$${Number(v).toFixed(2)}`} />],
      ['Category', <CellEditor key="c" label="Category" editor="select" value="Bread" options={['Bread', 'Pastry', 'Drinks']} onCommit={save} />],
      ['SKU', <CellEditor key="s" label="SKU" machine value="BRD-0042" onCommit={save} />],
      ['Created', <CellEditor key="d" label="Created" value="2026-03-04" disabled onCommit={save} />],
    ]} />
  );
}

When to use it

Use it when

  • Details pages where one or two values change often: a price, a name.
  • onCommit saves; throw an Error with a message to say why it was not saved.

Do not use it when

  • Forms of several fields saved together: use a Form with a SaveBar.
  • Values that need a long explanation to change: use a Dialog.

For everyone

  • The value is a button named «Edit Price: 12».
  • Enter saves, Escape puts the old value back, and the focus returns to the value.
  • A failed save is announced, with the reason in words.

Props

CellEditorTypeDefault
labelrequired

What the value is: «Price». It names the button and the field.

string
onCommitrequired

Saves the new value. Throw an Error with a message to say why it was not saved.

(value: string) => void | Promise<void>
valuerequired string | number | null
disabled boolean
editor "number" | "text" | "select" text
machine

Machine text (ids, keys): set in the mono face.

boolean
options DataOption[]
render

How the value is drawn when it is not being edited.

((value: string | number | null) => ReactNode)
  1. Details of a product
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms