Skip to content

EditableText

Text that becomes a field when pressed, for names in the page itself: a project, a table, a dashboard. Enter or leaving the field saves; Escape puts it back.

import { EditableText } from '@sypnia/ui/react'

On this page
  1. A project title
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

A project title

Press the title, change it and press Enter.

Created 3 days ago · Frankfurt

Code
import { useState } from 'react';
import { EditableText } from '@sypnia/ui/react';

// The title reads as a title. Press it to rename; Enter or leaving the field saves, Escape puts it back.
export default function Title() {
  const [name, setName] = useState('Storefront');
  return (
    <div className="sy-stack">
      <EditableText as="h2" label="Project name" value={name} validate={(v) => (v ? undefined : 'Write a name.')}
        onSave={async (v) => { await new Promise((r) => setTimeout(r, 600)); setName(v); }} />
      <p className="sy-text--muted">Created 3 days ago · Frankfurt</p>
    </div>
  );
}

Skeleton

The real piece and its skeleton: the same box, so nothing moves when the data arrives.

Code
import { EditableText, EditableTextSkeleton } from '@sypnia/ui/react';

// The title and its skeleton: the same heading, so the page does not move when the name arrives.
export default function Skeleton() {
  return (
    <div className="sy-grid">
      <EditableText as="h2" label="Project name" value="Storefront" onSave={() => {}} />
      <EditableTextSkeleton as="h2" />
    </div>
  );
}

When to use it

Use it when

  • The title of a page that its owner can rename.
  • Keep the heading level with as: a page title stays an h1 or h2.

Do not use it when

  • Text people do not expect to change: they will press it by accident.
  • Long text: use a Textarea in a Form.

For everyone

  • It is a button inside the heading, named with the text and «Edit Project name».
  • The pencil shows on hover and focus, and always on touch screens.

Props

EditableTextTypeDefault
labelrequired string
onSaverequired (value: string) => void | Promise<void>
valuerequired string
as

The element it reads as when not editing: a heading keeps its level.

"span" | "h1" | "h2" | "h3" span
loading

The text is on its way: a bar the height of the text, in the same heading.

boolean
placeholder string
validate ((value: string) => string)
  1. A project title
  2. Skeleton
  3. When to use it
  4. For everyone
  5. Props

    Search pages, sections and terms