A lightweight and flexible JavaScript/TypeScript library for adding in-place editing functionality to HTML elements.
- 🖊️ Make any HTML element in-place editable
- ⚙️ CSM and ESM and TypeScript support
- ⌨️ Configurable editing classname and submit shortcut key
- ♿ Built-in accessibility support
- 🔧 Flexible event callbacks
npm install edit-element
import { EditElement } from 'edit-element';
// Make all elements with .editable class in-place editable
const editableElements = new EditElement('.editable');
import EditElement from 'edit-element';
// Make all elements with .editable class editable
const editableElements = new EditElement('.editable', {
onEnter: (element) => {
console.log('Editing started', element);
},
onSubmit: (element) => {
console.log('Edit submitted', element.textContent);
},
onLeave: (element) => {
console.log('Editing ended', element);
},
editingElementClassName: 'editing',
submitKey: 'Enter',
});
Property | Type | Required | Default | Description |
---|---|---|---|---|
onEnter |
(element: HTMLElement) => void |
Optional | undefined |
Callback function when editing starts |
onSubmit |
(element: HTMLElement) => void |
Optional | undefined |
Callback function when edit is submitted |
onLeave |
(element: HTMLElement) => void |
Optional | undefined |
Callback function when editing ends |
editingElementClassName |
string |
Optional | undefined |
CSS class name added during editing |
submitKey |
string |
Optional | 'Enter' |
Key to trigger submission |
Remove all editable elements.
editableElements.destroyAllEditable();
Remove all editable elements by matching the specific querySelector query.
editableElements.destroyTargetEditable('.specific-editable');
MIT License
Issues and pull requests are welcome!