nook
Browse the docs

Components

Editable

Native

Edit a value in place with a draft, explicit save, cancel and focus return.

See the prompt
Project name

Installation

npx nook-ui@latest add editable

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Editable" component to this project, exactly as Nook ships it.

Edit a value in place with a draft, explicit save, cancel and focus return.

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add editable`. It writes `components/ui/editable.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/editable.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
"use client";

import { Editable } from "@/components/ui/editable";

export default function Example() {
  return <div className="grid w-full max-w-xl min-w-0 gap-4"><Editable label="Project name" defaultValue="Autumn release" required /></div>;
}
```

API
- `Editable`: Edit a value in place with a draft, explicit save, cancel and focus return.
  - `label` (`string`): Visible field name.
  - `value / defaultValue` (`string`): Committed value; drafts do not notify until saved.
  - `onValueChange` (`(value: string) => void`): Receives the saved draft.
  - `required` (`boolean`): Prevents committing a blank value.
  - `disabled` (`boolean`): Prevents editing.
  - `name` (`string`): Name for the hidden committed form value.
  - `...props` (`React.HTMLAttributes`): Native attributes on the root, with className merged and ref forwarded.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Enter saves and Escape cancels. The edit trigger regains focus after either action.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

"use client";

import { Editable } from "@/components/ui/editable";

export default function Example() {
  return <div className="grid w-full max-w-xl min-w-0 gap-4"><Editable label="Project name" defaultValue="Autumn release" required /></div>;
}

Props

Editable

Edit a value in place with a draft, explicit save, cancel and focus return.

PropTypeDefaultDescription
labelstring–Visible field name.
value / defaultValuestring–Committed value; drafts do not notify until saved.
onValueChange(value: string) => void–Receives the saved draft.
requiredboolean–Prevents committing a blank value.
disabledboolean–Prevents editing.
namestring–Name for the hidden committed form value.
...propsReact.HTMLAttributes–Native attributes on the root, with className merged and ref forwarded.

Accessibility

Enter saves and Escape cancels. The edit trigger regains focus after either action.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.