

# EditableText

Text that turns into an input on demand. Wrap the display element (a `Heading`, `Text`, or any element that accepts children) and the input takes its place, inheriting the same font, size and color so nothing shifts.

## Examples

### Default

Double-click the heading, or focus it and press Enter or F2. Enter or clicking away commits; Escape cancels.

```tsx
import { useState } from 'react';
import { EditableText, Heading } from '@var-ui/react';

function PlaylistName() {
  const [name, setName] = useState('Road trip');
  return (
    <EditableText value={name} onCommit={setName} aria-label="Playlist name">
      <Heading level={2}>{name}</Heading>
    </EditableText>
  );
}
```

```astro
<!-- No Astro binding yet — use @var-ui/react -->
```

```html
<!-- No HTML demo yet — use @var-ui/react -->
```

### Activation

`activation` controls what starts editing with the pointer: `doubleClick` (default), `click`, or `focus`. Enter and F2 start editing from the keyboard in every mode.

## Props

| Name | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| onCommit | (value: string) => void | yes |  | Called with the new text on Enter or blur, when it differs from `value`. |
| value | string | yes |  | Current committed text. |
| activation | EditableTextActivation \| undefined | no | doubleClick | What starts editing with the pointer. Enter and F2 always start editing from the keyboard. |
| aria-label | string \| undefined | no |  | Defines a string value that labels the current element. Accessible name for the input. Defaults to the current value, or `emptyLabel` when that is empty. |
| children | ReactNode | no |  | Display element (for example a `Heading`). Its typography is inherited by the input. |
| className | string \| undefined | no |  | Additional CSS class names merged onto the root element. |
| disabled | boolean \| undefined | no |  | Prevents editing. |
| emptyLabel | string \| undefined | no | 'Edit text' | Accessible name of the input when there is neither `aria-label` nor a value. |
| onCancel | (() => void) \| undefined | no |  | Called when editing is abandoned with Escape. |
| onValueChange | ((value: string) => void) \| undefined | no |  | Called with the draft text on every keystroke while editing. |
| readOnly | boolean \| undefined | no |  | Shows the text without allowing it to be edited. |
| ref | Ref<HTMLDivElement> \| undefined | no |  | Ref to the root `<div>`: the focusable element that starts editing. The `<input>` only exists while editing, so it cannot own a stable ref. |

## Accessibility

While not editing, the root is a focusable `role="group"` so keyboard users can reach it and press Enter or F2 to edit. While editing, the input is labelled by `aria-label` (falling back to the current value). Focus returns to the root after Enter or Escape; blur commits without moving focus. Disabled and read-only instances render the display element as-is and are not focusable.

`onCommit` is not called when the text is unchanged. Empty text is passed through, so reject or restore it in `onCommit` if blank values are not allowed.


> Also accepts all standard HTML attributes (ARIA attributes, event handlers, styles, …). Run `var-ui component editable-text --all-props` for the complete list.
