Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

UIComponentsReact

Editable

A text shown in place that turns into a field when pressed, with buttons to edit, save and cancel.

Built on the headless Editable.See its API in Docs

Rendered by React 19.3.1

editable.tsx

Installation

npx shadcn@4.23.0 add https://hamur.dev/r/react/editable.json

It also adds utils, button. The app needs its setup first: Installation.

Usage

Put an EditablePreview and an EditableInput inside Editable, and add an EditableEditTrigger, an EditableSubmitTrigger and an EditableCancelTrigger beside them for buttons that edit, save and cancel. The Preview shows the value, or the Root's placeholder while it is empty, and the Input replaces it while editing; render the Input as a textarea for a multiline value, and set autoResize to size it to its text. Name the field with a Field label or aria-label. A press, Enter or Space on the Preview starts an edit, Enter saves and Escape cancels; the activation and submit modes, the refusals, the focus and the announcements come from the headless Editable.

import {
  Editable,
  EditableCancelTrigger,
  EditableEditTrigger,
  EditableInput,
  EditablePreview,
  EditableSubmitTrigger,
} from '@/components/ui/editable'

Examples

Default

A display name with the pencil that edits it, and Save and Cancel while it is edited.

Its preview and code are at the top of the page.

Multiline

A bio in a textarea that grows with its text; Ctrl+Enter or Cmd+Enter saves it.

Rendered by React 19.3.1

editable-multiline.tsx

The Preview has the Input's box with a transparent border, so starting an edit moves nothing: it shows the border and a fill on hover and a ring on focus, keeps the text's line breaks, and stays at least 24 by 24 CSS pixels while empty so it can still be pressed. A read-only or disabled Preview shows no hover. The Input is the Input's box and turns destructive while a save is refused. The triggers are the Button's ghost icon-xs, 24 by 24 CSS pixels, so they meet the target size of WCAG 2.5.8. This item takes Base UI's component ID as its slug and one name per Base UI part.

API reference

The styled parts pass every prop to the headless part they wrap and add classes. The props, data attributes and keyboard are on Editable's API reference.