Checkbox

API reference for the "Checkbox" control.

Renders a checkbox within the Canva UI.

To learn how controls work, refer to Rich controls.

Usage

canva.create('checkbox', {
id: 'checkboxExample',
label: 'Checkbox Example',
disabled: false,
checked: false,
});

Parameters

Name

Type

Required

Description

controlType

string

Yes

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

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.

opts.disabled

boolean

No

If true, the checkbox is disabled. The default value is false.

opts.checked

boolean

No

If true, the checkbox is checked. The default value is false.

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 "checkbox".

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 "changed".

opts.message.message.checked

boolean

Yes

If true, the user has checked the checkbox. If false, the user has unchecked the checkbox.

Example

const canva = window.canva.init();
const state = {
checkboxExample: false,
};
canva.onReady(() => {
renderControls();
});
canva.onControlsEvent(async (opts) => {
if (!opts.message.commit) {
return;
}
if (opts.message.controlType === 'checkbox') {
state[opts.message.controlId] = opts.message.checked;
}
renderControls();
});
function renderControls() {
const controls = [
canva.create('checkbox', {
id: 'checkboxExample',
label: state.checkboxExample
? 'The checkbox is checked'
: 'The checkbox is not checked',
disabled: false,
checked: state.checkboxExample,
}),
];
canva.updateControlPanel(controls);
}