# @salmonui/editors/inline-edit API reference

> 20 exported symbols of @salmonui/editors/inline-edit: 1 function, 13 interfaces, 5 types and 1 constant.

Canonical: https://salmonui.dev/docs/reference/editors/inline-edit

```ts
import { … } from '@salmonui/editors/inline-edit';
```

## Functions

### InlineEdit

Kind: function

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEdit

```ts
function InlineEdit<T = string>(props: InlineEditProps<T>): ReactElement;
```

## Interfaces

### InlineEditActionsContext

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditActionsContext

```ts
interface InlineEditActionsContext {
    readonly save: () => void;
    readonly cancel: () => void;
    readonly pending: boolean;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `save` | `readonly save: () => void;` |  |  |
| `cancel` | `readonly cancel: () => void;` |  |  |
| `pending` | `readonly pending: boolean;` |  |  |

### InlineEditApi

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditApi

```ts
interface InlineEditApi {
    readonly element: HTMLSpanElement | null;
    startEdit(): void;
    save(): Promise<boolean>;
    cancelEdit(): void;
    validate(): Promise<readonly string[]>;
}
```

Ref handle: the Data Grid edit method names.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `readonly element: HTMLSpanElement \| null;` |  | The root element. |
| `startEdit` | `startEdit(): void;` |  |  |
| `save` | `save(): Promise<boolean>;` |  | Saves the draft; resolves to true when the value was saved. |
| `cancelEdit` | `cancelEdit(): void;` |  |  |
| `validate` | `validate(): Promise<readonly string[]>;` |  | Validates the draft (or the saved value when idle) and resolves to the error list. |

### InlineEditCancelEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditCancelEvent

```ts
interface InlineEditCancelEvent<T> {
    readonly value: T;
    readonly source: InlineEditSource;
    readonly trigger: InlineEditTrigger;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: T;` |  | The discarded draft. |
| `source` | `readonly source: InlineEditSource;` |  |  |
| `trigger` | `readonly trigger: InlineEditTrigger;` |  |  |

### InlineEditCancellable

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditCancellable

```ts
interface InlineEditCancellable {
    readonly defaultPrevented: boolean;
    preventDefault(): void;
}
```

A cancellable event (`preventDefault()` vetoes the step).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |
| `preventDefault` | `preventDefault(): void;` |  |  |

### InlineEditDraftChangeEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditDraftChangeEvent

```ts
interface InlineEditDraftChangeEvent<T> {
    readonly value: T;
    readonly previousValue: T;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: T;` |  |  |
| `previousValue` | `readonly previousValue: T;` |  |  |

### InlineEditEditingChangeEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditEditingChangeEvent

```ts
interface InlineEditEditingChangeEvent {
    readonly source: InlineEditSource;
    readonly reason: 'start' | 'save' | 'cancel';
}
```

Second argument of `onEditingChange` (frozen).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: InlineEditSource;` |  |  |
| `reason` | `readonly reason: 'start' \| 'save' \| 'cancel';` |  |  |

### InlineEditInputProps

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditInputProps

```ts
interface InlineEditInputProps {
    readonly id: string;
    readonly value: string;
    readonly onChange: (event: {
        readonly target: {
            readonly value: string;
        };
    }) => void;
    readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
    readonly 'aria-invalid': true | undefined;
    readonly 'aria-describedby': string | undefined;
    readonly 'aria-label': string | undefined;
    readonly readOnly: boolean;
    readonly autoFocus: true;
}
```

Props for the edit element: spread them on an input or pass them to a Salmon field.

Members (9):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `id` | `readonly id: string;` |  |  |
| `value` | `readonly value: string;` |  |  |
| `onChange` | `readonly onChange: (event: {     readonly target: {         readonly value: string;     }; }) => void;` |  |  |
| `onKeyDown` | `readonly onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;` |  |  |
| `aria-invalid` | `readonly 'aria-invalid': true \| undefined;` |  |  |
| `aria-describedby` | `readonly 'aria-describedby': string \| undefined;` |  |  |
| `aria-label` | `readonly 'aria-label': string \| undefined;` |  |  |
| `readOnly` | `readonly readOnly: boolean;` |  |  |
| `autoFocus` | `readonly autoFocus: true;` |  |  |

### InlineEditLocaleText

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditLocaleText

```ts
interface InlineEditLocaleText {
    readonly save: string;
    readonly cancel: string;
    readonly edit: string;
    readonly empty: string;
    readonly saving: string;
    readonly saveFailed: string;
}
```

Text of the built-in parts.

Members (6):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `save` | `readonly save: string;` |  |  |
| `cancel` | `readonly cancel: string;` |  |  |
| `edit` | `readonly edit: string;` |  |  |
| `empty` | `readonly empty: string;` |  |  |
| `saving` | `readonly saving: string;` |  |  |
| `saveFailed` | `readonly saveFailed: string;` |  |  |

### InlineEditProps

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditProps

```ts
interface InlineEditProps<T = string> extends RootProps {
    readonly value?: T | undefined;
    readonly defaultValue?: T | undefined;
    readonly save?: ((value: T, options: {
        readonly signal: AbortSignal;
    }) => void | PromiseLike<void>) | undefined;
    readonly mode?: 'inline' | 'popover' | undefined;
    readonly trigger?: 'click' | 'doubleClick' | 'editButton' | undefined;
    readonly blurAction?: 'save' | 'cancel' | 'keep' | undefined;
    readonly saveOnEnter?: boolean | undefined;
    readonly showActions?: boolean | undefined;
    readonly renderActions?: ((context: InlineEditActionsContext) => ReactNode) | undefined;
    readonly validation?: InlineEditValidation<T> | undefined;
    readonly placeholder?: ReactNode;
    readonly renderPreview?: ((context: {
        readonly value: T;
        readonly placeholder: ReactNode;
    }) => ReactNode) | undefined;
    readonly label?: string | undefined;
    readonly editing?: boolean | undefined;
    readonly defaultEditing?: boolean | undefined;
    readonly onEditingChange?: ((editing: boolean, event: InlineEditEditingChangeEvent) => void) | undefined;
    readonly disabled?: boolean | undefined;
    readonly name?: string | undefined;
    readonly popoverProps?: {
        readonly placement?: Placement | undefined;
        readonly offset?: number | undefined;
    } | undefined;
    readonly localeText?: Partial<InlineEditLocaleText> | undefined;
    readonly className?: string | undefined;
    readonly style?: CSSProperties | undefined;
    readonly classNames?: Partial<Record<InlineEditPart, string>> | undefined;
    readonly styles?: Partial<Record<InlineEditPart, CSSProperties>> | undefined;
    readonly ref?: Ref<InlineEditApi> | undefined;
    readonly children?: ((context: InlineEditRenderContext<T>) => ReactNode) | undefined;
    readonly onBeforeEditStart?: ((event: InlineEditStartEvent & InlineEditCancellable) => void) | undefined;
    readonly onEditStart?: ((event: InlineEditStartEvent) => void) | undefined;
    readonly onBeforeSave?: ((event: InlineEditSaveEvent<T> & InlineEditCancellable) => void) | undefined;
    readonly onSave?: ((event: InlineEditSaveEvent<T>) => void) | undefined;
    readonly onSaveError?: ((event: InlineEditSaveErrorEvent<T>) => void) | undefined;
    readonly onBeforeEditCancel?: ((event: InlineEditCancelEvent<T> & InlineEditCancellable) => void) | undefined;
    readonly onEditCancel?: ((event: InlineEditCancelEvent<T>) => void) | undefined;
    readonly onDraftChange?: ((event: InlineEditDraftChangeEvent<T>) => void) | undefined;
}
```

Members (34):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value?: T \| undefined;` | optional | Saved value (controlled). |
| `defaultValue` | `readonly defaultValue?: T \| undefined;` | optional | Initial saved value when uncontrolled. Default `''`. |
| `save` | `readonly save?: ((value: T, options: {     readonly signal: AbortSignal; }) => void \| PromiseLike<void>) \| undefined;` | optional | Persists a value. May return a promise: pending state, abort on cancel or unmount, rejection keeps editing. |
| `mode` | `readonly mode?: 'inline' \| 'popover' \| undefined;` | optional | `'popover'` (default) opens the editor in a non-modal dialog anchored to the preview; `'inline'` replaces the preview. |
| `trigger` | `readonly trigger?: 'click' \| 'doubleClick' \| 'editButton' \| undefined;` | optional | What starts editing. Default `'click'`. |
| `blurAction` | `readonly blurAction?: 'save' \| 'cancel' \| 'keep' \| undefined;` | optional | What focus leaving the editor does. Default `'save'`. |
| `saveOnEnter` | `readonly saveOnEnter?: boolean \| undefined;` | optional | Enter saves (Mod+Enter in a textarea). Default true. |
| `showActions` | `readonly showActions?: boolean \| undefined;` | optional | Shows the Save and Cancel buttons. Default true. |
| `renderActions` | `readonly renderActions?: ((context: InlineEditActionsContext) => ReactNode) \| undefined;` | optional | Replaces the default actions. |
| `validation` | `readonly validation?: InlineEditValidation<T> \| undefined;` | optional |  |
| `placeholder` | `readonly placeholder?: ReactNode;` | optional | Shown when the value is empty. Default `localeText.empty`. |
| `renderPreview` | `readonly renderPreview?: ((context: {     readonly value: T;     readonly placeholder: ReactNode; }) => ReactNode) \| undefined;` | optional | Display state content. Default `String(value)`. |
| `label` | `readonly label?: string \| undefined;` | optional | Field label: the accessible name of the preview and the editor. |
| `editing` | `readonly editing?: boolean \| undefined;` | optional | Editing state. |
| `defaultEditing` | `readonly defaultEditing?: boolean \| undefined;` | optional |  |
| `onEditingChange` | `readonly onEditingChange?: ((editing: boolean, event: InlineEditEditingChangeEvent) => void) \| undefined;` | optional |  |
| `disabled` | `readonly disabled?: boolean \| undefined;` | optional |  |
| `name` | `readonly name?: string \| undefined;` | optional | Form field name: a hidden input carries the saved value. |
| `popoverProps` | `readonly popoverProps?: {     readonly placement?: Placement \| undefined;     readonly offset?: number \| undefined; } \| undefined;` | optional | Popover placement and offset. |
| `localeText` | `readonly localeText?: Partial<InlineEditLocaleText> \| undefined;` | optional |  |
| `className` | `readonly className?: string \| undefined;` | optional |  |
| `style` | `readonly style?: CSSProperties \| undefined;` | optional |  |
| `classNames` | `readonly classNames?: Partial<Record<InlineEditPart, string>> \| undefined;` | optional |  |
| `styles` | `readonly styles?: Partial<Record<InlineEditPart, CSSProperties>> \| undefined;` | optional |  |
| `ref` | `readonly ref?: Ref<InlineEditApi> \| undefined;` | optional |  |
| `children` | `readonly children?: ((context: InlineEditRenderContext<T>) => ReactNode) \| undefined;` | optional | The edit element. Default: a text input. |
| `onBeforeEditStart` | `readonly onBeforeEditStart?: ((event: InlineEditStartEvent & InlineEditCancellable) => void) \| undefined;` | optional |  |
| `onEditStart` | `readonly onEditStart?: ((event: InlineEditStartEvent) => void) \| undefined;` | optional |  |
| `onBeforeSave` | `readonly onBeforeSave?: ((event: InlineEditSaveEvent<T> & InlineEditCancellable) => void) \| undefined;` | optional |  |
| `onSave` | `readonly onSave?: ((event: InlineEditSaveEvent<T>) => void) \| undefined;` | optional |  |
| `onSaveError` | `readonly onSaveError?: ((event: InlineEditSaveErrorEvent<T>) => void) \| undefined;` | optional |  |
| `onBeforeEditCancel` | `readonly onBeforeEditCancel?: ((event: InlineEditCancelEvent<T> & InlineEditCancellable) => void) \| undefined;` | optional |  |
| `onEditCancel` | `readonly onEditCancel?: ((event: InlineEditCancelEvent<T>) => void) \| undefined;` | optional |  |
| `onDraftChange` | `readonly onDraftChange?: ((event: InlineEditDraftChangeEvent<T>) => void) \| undefined;` | optional |  |

### InlineEditRenderContext

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditRenderContext

```ts
interface InlineEditRenderContext<T> {
    readonly value: T;
    readonly setValue: (value: T) => void;
    readonly inputProps: InlineEditInputProps;
    readonly save: () => void;
    readonly cancel: () => void;
    readonly pending: boolean;
    readonly errors: readonly string[];
}
```

Argument of the `children` render prop.

Members (7):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: T;` |  | The draft value. |
| `setValue` | `readonly setValue: (value: T) => void;` |  | Replaces the draft. |
| `inputProps` | `readonly inputProps: InlineEditInputProps;` |  | Wiring for a text-like input (`value` is the draft as a string). |
| `save` | `readonly save: () => void;` |  |  |
| `cancel` | `readonly cancel: () => void;` |  |  |
| `pending` | `readonly pending: boolean;` |  | True while `save` (or async validation) is pending. |
| `errors` | `readonly errors: readonly string[];` |  | Validation messages of the draft (empty when valid). |

### InlineEditSaveErrorEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditSaveErrorEvent

```ts
interface InlineEditSaveErrorEvent<T> {
    readonly value: T;
    readonly error: unknown;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: T;` |  |  |
| `error` | `readonly error: unknown;` |  |  |

### InlineEditSaveEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditSaveEvent

```ts
interface InlineEditSaveEvent<T> {
    readonly value: T;
    readonly previousValue: T;
    readonly source: InlineEditSource;
    readonly trigger: InlineEditTrigger;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `readonly value: T;` |  | The value being saved (the draft). |
| `previousValue` | `readonly previousValue: T;` |  | The saved value before this edit. |
| `source` | `readonly source: InlineEditSource;` |  |  |
| `trigger` | `readonly trigger: InlineEditTrigger;` |  |  |

### InlineEditStartEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditStartEvent

```ts
interface InlineEditStartEvent {
    readonly source: InlineEditSource;
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: InlineEditSource;` |  |  |

## Types

### InlineEditPart

Kind: type

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditPart

```ts
type InlineEditPart = 'preview' | 'editor' | 'actions' | 'error';
```

### InlineEditSource

Kind: type

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditSource

```ts
type InlineEditSource = 'pointer' | 'keyboard' | 'touch' | 'api';
```

Input that caused a lifecycle event.

### InlineEditTrigger

Kind: type

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditTrigger

```ts
type InlineEditTrigger = 'actions' | 'enter' | 'escape' | 'blur' | 'api';
```

What ended an edit: the action buttons, Enter, Escape, focus leaving, or a ref method.

### InlineEditValidation

Kind: type

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditValidation

```ts
type InlineEditValidation<T = unknown> = Omit<ColumnValidation, 'validate'> & {
    readonly validate?: InlineEditValidator<T> | readonly [
        InlineEditValidator<T>,
        string
    ] | readonly InlineEditValidator<T>[];
};
```

Validation rules: the Data Grid `column.validation` vocabulary,
evaluated by `@salmonui/core/validation`. Each rule value is the
argument or `[argument, message]`.

Members (18):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `required` | `required?: RuleValue<boolean>;` | optional, inherited |  |
| `min` | `min?: RuleValue<string \| number>;` | optional, inherited |  |
| `max` | `max?: RuleValue<string \| number>;` | optional, inherited |  |
| `range` | `range?: RuleValue<readonly [string \| number, string \| number]>;` | optional, inherited |  |
| `minLength` | `minLength?: RuleValue<number>;` | optional, inherited |  |
| `maxLength` | `maxLength?: RuleValue<number>;` | optional, inherited |  |
| `rangeLength` | `rangeLength?: RuleValue<readonly [number, number]>;` | optional, inherited |  |
| `number` | `number?: RuleValue<boolean>;` | optional, inherited |  |
| `digits` | `digits?: RuleValue<boolean>;` | optional, inherited |  |
| `email` | `email?: RuleValue<boolean>;` | optional, inherited |  |
| `url` | `url?: RuleValue<boolean>;` | optional, inherited |  |
| `date` | `date?: RuleValue<boolean>;` | optional, inherited |  |
| `dateIso` | `dateIso?: RuleValue<boolean>;` | optional, inherited |  |
| `creditcard` | `creditcard?: RuleValue<boolean>;` | optional, inherited |  |
| `tel` | `tel?: RuleValue<boolean>;` | optional, inherited |  |
| `pattern` | `pattern?: RuleValue<string \| RegExp>;` | optional, inherited | A pattern string or a RegExp, tested as a search: a partial match passes, so anchor the pattern (`^[A-Z]{3}$`) to require the whole value. |
| `messages` | `messages?: Partial<ValidationMessages>;` | optional, inherited | Message overrides of this column, keyed by rule name; they win over `edit.messages`. |
| `validate` | `validate?: InlineEditValidator<T> \| readonly InlineEditValidator<T>[] \| readonly [InlineEditValidator<T>, string];` | optional, inherited |  |

### InlineEditValidator

Kind: type

Page: https://salmonui.dev/docs/reference/editors/inline-edit/InlineEditValidator

```ts
type InlineEditValidator<T> = (value: T) => string | boolean | null | undefined | PromiseLike<string | boolean | null | undefined>;
```

Custom validator of `validation.validate`: an error message, or null / undefined / true when valid (false uses the default message). May be async.

## Constants

### INLINE_EDIT_DEFAULT_LOCALE_TEXT

Kind: const

Page: https://salmonui.dev/docs/reference/editors/inline-edit/INLINE_EDIT_DEFAULT_LOCALE_TEXT

```ts
const INLINE_EDIT_DEFAULT_LOCALE_TEXT: InlineEditLocaleText;
```

English defaults of `localeText`.
