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
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | number | — | The current value (required) |
onSave | (value: string | number) => void | Promise<void> | — | Save callback (required) |
onCancel | () => void | — | Cancel callback |
type | 'text' | 'number' | 'email' | 'url' | 'date' | 'text' | Input type |
validate | (value) => string | null | — | Validation function returning error or null |
placeholder | string | — | Placeholder text when empty |
disabled | boolean | false | Disable editing |
align | 'left' | 'center' | 'right' | 'left' | Text alignment |
format | (value) => string | — | Custom display formatter |
className | string | — | Additional 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 techKeyboard Navigation
| Key | Action |
|---|---|
| Tab | Focus the cell |
| Enter | Save changes |
| Escape | Cancel 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