Spanish Total.js
English
Documentation For AI agents
Contents

Edit text on the canvas

Let the user change the text of your component straight on the canvas.

.md GitHub
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

OptionMeaning
multilineEnter makes a new line; Shift+Enter ends.
formatAllows bold, italic, underline and links. On by default.
bold, italic, underline, linkfalse turns off one kind of formatting.
iconAllows inserting an icon. On when format is on.
placeholderAn 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.

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.

Made in Europe