@molecule/app-inline-edit-vue

Feature · inline-edit · App (browser) · v1.1.2 · Apache-2.0

Click-to-edit text + textarea + select with Save/Cancel

npm install @molecule/app-inline-edit-vue

npm · Source on GitHub

How it works

@molecule/app-inline-edit-vue is a ready-made inline-edit feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

import { createApp, defineComponent, h, ref } from 'vue'
import { InlineEdit } from '@molecule/app-inline-edit-vue'

const Deal = defineComponent({
  setup() {
    const title = ref('Acme renewal')
    return () =>
      h(InlineEdit, {
        value: title.value,
        onSubmit: async (next: string) => {
          title.value = next
        },
        placeholder: 'Enter deal title',
      })
  },
})

createApp(Deal).mount('#app')

Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue

Reference

Vue click-to-edit inline field.

Exports <InlineEdit> — the value rendered as text, with a click (or Tab + Enter) swapping in an <Input> or <Textarea> plus Save/Cancel buttons. Enter submits (Cmd/Ctrl+Enter for the textarea variant), Escape cancels. It is the Vue counterpart of @molecule/app-inline-edit-react: the same props (React names) and the same DOM for the same input.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

import { createApp, defineComponent, h, ref } from 'vue'
import { InlineEdit } from '@molecule/app-inline-edit-vue'

const Deal = defineComponent({
  setup() {
    const title = ref('Acme renewal')
    return () =>
      h(InlineEdit, {
        value: title.value,
        onSubmit: async (next: string) => {
          title.value = next
        },
        placeholder: 'Enter deal title',
      })
  },
})

createApp(Deal).mount('#app')

Type

feature

Installation

npm install @molecule/app-inline-edit-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue

API

Interfaces

InlineEditProps

Props accepted by the InlineEdit component.

interface InlineEditProps {
  /** Current value. */
  value: string
  /** Called when the user commits a new value. Return a Promise to block the UI while saving. */
  onSubmit: (next: string) => void | Promise<void>
  /** Render mode for the editor. */
  variant?: 'input' | 'textarea'
  /** Renderer for the read state — defaults to plain text. */
  renderRead?: (value: string) => VNodeChild
  /**
   * Placeholder when value is empty. Also becomes the editor field's
   * accessible label while editing; without it the field falls back to the
   * translated `inlineEdit.aria.edit` default.
   */
  placeholder?: string
  /** Extra classes. */
  className?: string
}

Constants

InlineEdit

Click-to-edit text. Renders the value as text by default; on click (or focus via tab + Enter) it swaps in an <Input> / <Textarea> for inline editing. Enter submits, Escape cancels.

const InlineEdit: DefineComponent<
  ExtractPropTypes<{
    value: { type: StringConstructor; required: true }
    onSubmit: { type: PropType<InlineEditProps['onSubmit']>; required: true }
    variant: { type: PropType<'input' | 'textarea'>; default: string }
    renderRead: PropType<InlineEditProps['renderRead']>
    placeholder: StringConstructor
    className: StringConstructor
  }>,
  () => VNode,
  {},
  {},
  {},
  ComponentOptionsMixin,
  ComponentOptionsMixin,
  {},
  string,
  PublicProps,
  Readonly<
    ExtractPropTypes<{
      value: { type: StringConstructor; required: true }
      onSubmit: { type: PropType<InlineEditProps['onSubmit']>; required: true }
      variant: { type: PropType<'input' | 'textarea'>; default: string }
      renderRead: PropType<InlineEditProps['renderRead']>
      placeholder: StringConstructor
      className: StringConstructor
    }>
  > &
    Readonly<{}>,
  { variant: 'input' | 'textarea' },
  {},
  {},
  {},
  string,
  ComponentProvideOptions,
  true,
  {},
  any
>
  • props — Component props (see InlineEditProps).

Returns: The inline-edit component.

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-vue ^1.1.0
  • @molecule/app-vue ^3.5.0 || ^4.0.0
  • vue ^3.4.0

Runtime Dependencies

  • @molecule/app-ui

  • @molecule/app-ui-vue

  • @molecule/app-vue

  • vue

  • Requires a bonded ClassMap (getClassMap() throws otherwise) and @molecule/app-vue's i18n provider (useTranslation() throws without it); button labels come from the @molecule/app-locales-inline-edit companion bond.

  • Return a Promise from onSubmit to disable the buttons while saving. If onSubmit REJECTS, the editor stays open with the draft intact but the error is not displayed — catch and surface errors inside your onSubmit (toast, form error, etc.).

  • The draft re-syncs from value whenever the prop changes, including mid-edit — avoid mutating value while the user is typing.

Translations

Translation strings are provided by @molecule/app-locales-inline-edit.