Button
API reference for the "Button" control.
Render a button within the Canva UI.
To learn how controls work, refer to Rich controls.

Usage

1
canva.create("button", {
2
id: "myAmazingButton",
3
label: "My Amazing Button",
4
});
Copied!

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

1
const canva = window.canva.init();
2
3
const state = {
4
clicks: 0,
5
};
6
7
canva.onReady(() => {
8
renderControls();
9
});
10
11
canva.onControlsEvent(async (opts) => {
12
if (opts.message.controlId === "clickCounter") {
13
state.clicks = state.clicks + 1;
14
}
15
16
renderControls();
17
});
18
19
function renderControls() {
20
const controls = [
21
canva.create("button", {
22
id: "clickCounter",
23
label: `${state.clicks} clicks`,
24
}),
25
];
26
27
canva.updateControlPanel(controls);
28
}
Copied!
Last modified 3d ago