Skip to content

Editable Content ​

A component that allows content to be edited inline, switching between display and edit modes.

Usage ​

html
<editable-content 
  v-model="content"
  :edit-mode="isEditing"
  @save="handleSave"
  @cancel="handleCancel"
></editable-content>

Props ​

PropTypeDefaultDescription
modelValuestringRequiredContent value (v-model)
editModebooleanfalseWhether to show in edit mode
type'text' | 'textarea' | 'rich-text''text'Editor type
placeholderstring'Click to edit'Placeholder text in edit mode
readonlybooleanfalseWhether content is read-only
maxLengthnumberundefinedMaximum character limit
showEditButtonbooleantrueWhether to show edit button
saveOnBlurbooleantrueWhether to save when editor loses focus

Events ​

EventPayloadDescription
savevalueEmitted when content is saved
cancelnoneEmitted when edit is cancelled
editnoneEmitted when entering edit mode
update:modelValuestringEmitted when content changes

Features ​

  • Inline Editing: Seamlessly switch between display and edit modes
  • Multiple Types: Support for text, textarea, and rich text editing
  • Auto-save: Optional save on blur functionality
  • Validation: Built-in character limit and validation
  • Accessibility: Proper focus management and keyboard shortcuts

Examples ​

Basic Editable Text ​

html
<script setup>
const title = ref('My Document Title')

function handleSave(newTitle) {
  ElMessage.success('Title updated!')
}
</script>

<template>
  <h2>
    <editable-content 
      v-model="title"
      type="text"
      @save="handleSave"
    />
  </h2>
</template>

Textarea Editing ​

html
<script setup>
const description = ref('This is a product description...')
</script>

<template>
  <editable-content 
    v-model="description"
    type="textarea"
    :rows="4"
    placeholder="Enter product description..."
    @save="updateDescription"
  />
</template>

Rich Text Editing ​

html
<editable-content 
  v-model="articleContent"
  type="rich-text"
  :edit-mode="editingArticle"
  @save="saveArticle"
  @cancel="cancelEdit"
>
  <template #display="{ content }">
    <div v-html="content" class="article-content"></div>
  </template>
</editable-content>

With Character Limit ​

html
<editable-content 
  v-model="tweet"
  type="textarea"
  :max-length="280"
  placeholder="What's happening?"
  @save="postTweet"
/>

Read-only Mode ​

html
<editable-content 
  v-model="staticContent"
  readonly
  :show-edit-button="false"
/>

Custom Edit Button ​

html
<editable-content 
  v-model="customContent"
  @edit="startEditing"
>
  <template #edit-button="{ onClick }">
    <el-button 
      size="small" 
      type="primary" 
      @click="onClick"
      icon="edit"
    >
      Customize
    </el-button>
  </template>
</editable-content>

© Velocitech LTD. All rights reserved.

Build SaaS Products Without Limits.