Inline Edit

View as Markdown

Text you change where it sits, such as a title: press it, type, Enter saves and Escape puts it back.

Press the name to rename it.

When to use

Text you change where it sits, such as a title: press it, type, Enter saves and Escape puts it back. Use Input instead when the field is part of a form with a Save button.

Usage

import { InlineEdit } from "./ui/uicontext/components/InlineEdit.ts"
const Message = UiSchema.TaggedEnum({ Renamed: { value: Schema.String } })export const Title = (h: Html.H<typeof Message.Type>, title: string) =>	InlineEdit(h, { key: "title", props: { value: title, label: "Dashboard name", size: "title" }, onEmit: { Committed: ({ value }) => Message.Renamed({ value }) } })

Examples

Rows in a list

Enter or leaving the field saves; Escape puts the old text back. Empty text isn't saved.

  • $3,200.00
  • $5,750.00
  • $1,800.00

API reference

Props

InlineEdit props
NameTypeDefaultDescription
valuerequiredstring——
labelrequiredstring—What the text is, for the button and the input: "Project name"
placeholderstring—Shown, quieter, while the value is empty: "Untitled"
allowEmptyboolean—Saves empty text too
maxLengthnumber—The most characters
size"body" | "title"bodyHow big the text reads: a heading or body text; body by default
disabledboolean——

Events

InlineEdit events
EventPayloadDescription
Committed{ value: string }The new text, trimmed, when it changed

Keyboard and accessibility

KeysDoes
Enter SpaceOn the text, start editing with it selected
EnterSave
EscapePut the old text back
TabSave and move on

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/inline-edit

Source