Button

API reference for the "Button" control.

Render a button within the Canva UI.

To learn how controls work, refer to Rich controls.

Usage

canva.create('button', {
id: 'myAmazingButton',
label: 'My Amazing Button',
});

Parameters

Name

Type

Required

Description

controlType

string

Yes

The type of control. To create a button, the value must be "button".

opts

object

Yes

Properties for configuring the control.

opts.id

string

Yes

A unique ID for the control.

opts.label

string

Yes

A human readable label for the control.

Event

Name

Type

Required

Description

opts

object

Yes

Information about the event.

opts.message

object

Yes

Information about the event.

opts.message.commit

boolean

Yes

The value of this property is always true.

opts.message.controlId

string

Yes

The id of the control.

opts.message.controlType

string

Yes

The type of control. The value of this property is always "button".

opts.message.message

object

Yes

Additional information about the event.

opts.message.message.type

string

Yes

The type of event. The value of this property is always "click".

Example

const canva = window.canva.init();
const state = {
clicks: 0,
};
canva.onReady(() => {
renderControls();
});
canva.onControlsEvent(async (opts) => {
if (opts.message.controlId === 'clickCounter') {
state.clicks = state.clicks + 1;
}
renderControls();
});
function renderControls() {
const controls = [
canva.create('button', {
id: 'clickCounter',
label: `${state.clicks} clicks`,
}),
];
canva.updateControlPanel(controls);
}