# InlineEdit

> Text that can be edited in place: activate it to type, press Enter to save or Escape to cancel.

Category: Forms · Status: stable · Package: @bindshq/stance-react@0.1.1 · Docs: https://stanceui.com/components/inline-edit

Use InlineEdit for a single value people change now and then where they read it: a template name, a document title, a short note. For several related fields, or values that need explanation, use a form with FormField instead.

## Import

```tsx
import { InlineEdit } from '@bindshq/stance-react';
```

Styles are imported once per app: `@bindshq/stance-tokens/css` and `@bindshq/stance-react/styles.css`.

## Examples

### Template name

```tsx
import * as React from 'react';
import { InlineEdit } from '@bindshq/stance-react';

export function Basic() {
  const [name, setName] = React.useState('Sales team signature');
  return <InlineEdit label="template name" value={name} onCommit={setName} size="lg" />;
}
```

### Validation

validate returns an error message to reject a value. The editor stays open so it can be fixed.

```tsx
import * as React from 'react';
import { InlineEdit } from '@bindshq/stance-react';

export function WithValidation() {
  const [name, setName] = React.useState('Master services agreement');
  return (
    <InlineEdit
      label="document title"
      value={name}
      onCommit={setName}
      validate={(v) =>
        v.length < 3
          ? 'Enter at least 3 characters.'
          : v.length > 60
            ? 'Keep the title under 60 characters.'
            : undefined
      }
    />
  );
}
```

### Confirm and cancel buttons

With showActions, leaving the field no longer saves; people choose explicitly.

```tsx
import * as React from 'react';
import { InlineEdit } from '@bindshq/stance-react';

export function WithActions() {
  const [domain, setDomain] = React.useState('binds.si');
  return <InlineEdit label="reply-to domain" value={domain} onCommit={setDomain} showActions />;
}
```

### Multiline

Enter adds a line and Ctrl/⌘+Enter saves.

```tsx
import * as React from 'react';
import { InlineEdit } from '@bindshq/stance-react';

export function Multiline() {
  const [note, setNote] = React.useState('Countersign by Friday.\nSend a copy to legal@binds.si.');
  return (
    <div style={{ width: '100%', maxWidth: 420 }}>
      <InlineEdit label="note" value={note} onCommit={setNote} multiline placeholder="Add a note" />
    </div>
  );
}
```

### Sizes and empty state

```tsx
import { InlineEdit } from '@bindshq/stance-react';

export function Sizes() {
  return (
    <div style={{ display: 'grid', gap: 12, justifyItems: 'start' }}>
      <InlineEdit label="team" defaultValue="Legal" size="sm" />
      <InlineEdit label="owner" defaultValue="Priya Nair" size="md" />
      <InlineEdit label="job title" placeholder="Add a job title" size="md" />
      <InlineEdit label="reference" defaultValue="MSA-2026-014" readOnly />
    </div>
  );
}
```

## API reference

| Component | Prop | Type | Default | Description |
| --- | --- | --- | --- | --- |
| InlineEdit | `label` (required) | `string` | None | What is being edited, e.g. "template name". Names the read view “Edit <label>” and the input. |
| InlineEdit | `value` | `string` | None | Controlled committed value. |
| InlineEdit | `defaultValue` | `string` | `''` | Initial value when uncontrolled. |
| InlineEdit | `onCommit` | `(value: string) => void` | None | Called with the new value when it changes and is saved. |
| InlineEdit | `onCancel` | `() => void` | None | Called when editing is cancelled. |
| InlineEdit | `validate` | `(value: string) => string \| undefined` | None | Return an error message to reject the value and keep editing. |
| InlineEdit | `placeholder` | `string` | `'Add a value'` | Shown in the read view when the value is empty. |
| InlineEdit | `multiline` | `boolean` | `false` | Edit in a textarea. |
| InlineEdit | `showActions` | `boolean` | `false` | Show Save and Cancel buttons while editing. |
| InlineEdit | `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Text size, to match the surrounding content. |
| InlineEdit | `trim` | `boolean` | `true` | Trim whitespace before saving. |
| InlineEdit | `defaultEditing` | `boolean` | `false` | Start in edit mode. |
| InlineEdit | `disabled` | `boolean` | `false` | Shows the value as a disabled button. |
| InlineEdit | `readOnly` | `boolean` | `false` | Shows the value as plain text with no edit affordance. |
| InlineEdit | `labels` | `Partial<InlineEditLabels>` | None | Translations for the Save and Cancel buttons. |

## Accessibility

- The read view is a real button named “Edit <label>: <value>”, so it is reachable by keyboard and announces what activating it does.
- Entering edit mode moves focus to the input and selects the text; saving or cancelling returns focus to the read view.
- Validation errors are linked to the input and announced immediately, and the editor stays open.
- The pencil icon appears on hover and focus, and is always visible on touch screens where there is no hover.
- With showActions, Save and Cancel are labelled buttons that stay inside the editor’s focus area.

## Keyboard

| Keys | Action |
| --- | --- |
| `Enter` `Space` | On the read view: starts editing. |
| `Enter` | While editing: saves. In multiline mode it adds a line. |
| `Ctrl/⌘` `Enter` | In multiline mode: saves. |
| `Esc` | Cancels and restores the previous value. |
| `Tab` | Leaves the field, saving the value (unless showActions is on). |

## Guidelines

**Do**

- Use a specific label: “template name”, not “value”.
- Use showActions when a change has consequences people should confirm.

**Don’t**

- Use it for several fields that are saved together; use a form.
- Rely on it for required information that has no value yet; ask for it in a form.

## Related

- https://stanceui.com/components/input
- https://stanceui.com/components/textarea
- https://stanceui.com/components/form-field
