Editable Cell

Forms
Data Display

Inline editable cell with validation, type support, and save/cancel actions.

Preview

Click on the cell to edit its value

Click to edit

Input Types

Support for text, number, email, url, and date inputs

Click to edit
42
user@example.com

With Validation

Custom validation with error messages

99.99
johndoe

Alignment Options

Left, center, or right text alignment

Left aligned text
Centered text
$1,234.56

Custom Formatting

Format display values differently from stored values

$99.99
75%

Disabled State

Prevent editing with the disabled prop

Cannot edit this

Props

EditableCell component API reference

PropTypeDefaultDescription
valuestring | numberThe current value (required)
onSave(value: string | number) => void | Promise<void>Save callback (required)
onCancel() => voidCancel callback
type'text' | 'number' | 'email' | 'url' | 'date''text'Input type
validate(value) => string | nullValidation function returning error or null
placeholderstringPlaceholder text when empty
disabledbooleanfalseDisable editing
align'left' | 'center' | 'right''left'Text alignment
format(value) => stringCustom display formatter
classNamestringAdditional CSS classes for container

Usage

Import and implementation example

import { EditableCell } from '@/blocks/data-display/editable-cell'

export default function Example() {
  const [value, setValue] = useState('Click to edit')

  return (
    <>
      {/* Basic editable cell */}
      <EditableCell
        value={value}
        onSave={(newValue) => setValue(newValue)}
      />

      {/* With type validation */}
      <EditableCell
        value={42}
        type="number"
        onSave={(value) => setNumber(Number(value))}
      />

      {/* With custom validation */}
      <EditableCell
        value={price}
        type="number"
        validate={(value) => {
          if (Number(value) < 0) return 'Must be positive'
          return null
        }}
        onSave={(value) => setPrice(Number(value))}
      />

      {/* With custom formatting */}
      <EditableCell
        value={99.99}
        type="number"
        format={(value) => `$${Number(value).toFixed(2)}`}
        onSave={(value) => setPrice(Number(value))}
      />

      {/* Alignment options */}
      <EditableCell
        value="Right aligned"
        align="right"
        onSave={(value) => setValue(String(value))}
      />

      {/* Disabled state */}
      <EditableCell
        value="Read only"
        disabled
        onSave={() => {}}
      />
    </>
  )
}

Features

Built-in functionality

  • Click to edit: Auto-focus and selection
  • Keyboard support: Enter to save, Escape to cancel
  • Validation: Custom validation with inline errors
  • Type coercion: Automatic type conversion for numbers
  • Async save: Support for async operations with loading
  • Custom formatting: Display formatted values while editing raw
  • Alignment: Left, center, right alignment
  • Dark mode: Full dark mode support

Accessibility

Accessibility considerations

ARIA Attributes

Uses native input elementError messages linked via aria-describedbyDisabled state communicated to assistive tech

Keyboard Navigation

KeyAction
TabFocus the cell
EnterSave changes
EscapeCancel and revert

Notes

  • Click or focus activates edit mode
  • Validation errors announced on blur
  • Save/cancel buttons are keyboard accessible
  • Focus trapped in edit mode until saved/cancelled