Edit text on the canvas
Let the user change the text of your component straight on the canvas.
On this page
Headline and Paragraph let the user double-click their text and type. Your component can do the same with instance.edit(). This works in the editor only.
Make text editable
exports.config = { html: 'Enter text' };
exports.make = function(instance, config, element) {
element.html('<p class="text">{0}</p>'.format(config.html));
element.on('dblclick', '.text', function(e) {
e.stopPropagation();
e.preventDefault();
instance.edit(this, { multiline: true });
});
instance.on('html', function() {
config.html = element.find('.text').html();
});
};instance.edit(el, options) makes the element editable. The user ends with Enter, Esc, Tab or a click outside. UI Builder then emits html, and the handler stores the new text in the configuration, so the design keeps it.
Options
| Option | Meaning |
|---|---|
multiline | Enter makes a new line; Shift+Enter ends. |
format | Allows bold, italic, underline and links. On by default. |
bold, italic, underline, link | false turns off one kind of formatting. |
icon | Allows inserting an icon. On when format is on. |
placeholder | An element that is hidden while the text is not empty. |
cursor | 'end' puts the cursor at the end of the text. |
With format on, the user makes a link of the selected text with Ctrl+L (Cmd+L on a Mac), and inserts an icon with Ctrl+P.
Icons and links
Paragraph also opens the icon picker when the user clicks an icon, and the link form when the user clicks a link:
element.on('click', '.ti', function() {
UIBuilder.emit('icon', this);
});
element.on('click', 'a', function(e) {
e.preventDefault();
UIBuilder.emit('link', this);
});After a change, UI Builder emits html on the instance, as after editing the text.