Skip to content
synccn

Editable Text

New

Click text to edit it in place; Enter saves and Esc cancels.

Q3 product roadmap

OwnerMichael
Budget$12,000

Click any value to edit. Enter saves, Esc cancels.

Installation

$ pnpm dlx shadcn@latest add @synccn/editable-text

First time in this project? Connect synccn with one command.

Usage

import { EditableText } from "@/components/ui/editable-text";<EditableText defaultValue="Q3 roadmap" />

API reference

Generated from the component's TypeScript types, so it always matches the code.

EditableText

Text that turns into a field when clicked. Enter saves, Escape cancels, and clicking away saves. Empty values are rejected.

  • value
    string

    Controlled value.

  • defaultValue
    string

    Default ""

    Initial value when uncontrolled.

  • onValueChange
    (value: string) => void

    Called with the saved value.

  • as
    React.ElementType

    Default "span"

    Element used to display the text.

  • placeholder
    string

    Default "Click to edit"

    Shown when empty.

  • validate
    (value: string) => string | undefined

    Return an error message to block saving.

  • inputClassName
    string

    Extra classes for the input.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Keyboard

  • EnterorF2Start editing
  • EnterSave
  • EscCancel

Accessibility

  • Clicking away also saves. Empty or invalid values are rejected and the old value is kept.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: button
  • ARIA attributes: aria-invalid, aria-label
  • Keys handled: Enter, Escape
  • Shows a visible focus ring for keyboard users