Select
API reference for the "Select" control.
Renders a dropdown within the Canva UI.
To learn how controls work, refer to Rich controls.

Usage

1
canva.create("select", {
2
id: "selectExample",
3
value: "apples",
4
options: [
5
{ value: "apples", label: "Apples" },
6
{ value: "bananas", label: "Bananas" },
7
{ value: "pears", label: "Pears" },
8
],
9
});
Copied!

Parameters

Name
Type
Required
Description
controlType
string
Yes
The type of control. To create a select, the value must be "select".
opts
object
Yes
Properties for configuring the control.
opts.id
string
Yes
A unique ID for the control.
opts.options
Yes
The options to render within the select control.
opts.value
string
No
The value of the selected option. This value must match thevalue property of one of the options.

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 "select".
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 "setValue".
opts.message.message.value
string
Yes
The value of the selected option.

Types

Option

Represents an individual option in a dropdown.
Properties
Name
Type
Required
Description
value
string
Yes
The value of the option.
label
string
Yes
A human readable label for the option.

Example

1
const canva = window.canva.init();
2
3
const state = {
4
selectExample: "apples",
5
};
6
7
canva.onReady(() => {
8
renderControls();
9
});
10
11
canva.onControlsEvent(async (opts) => {
12
if (!opts.message.commit) {
13
return;
14
}
15
16
if (opts.message.controlType === "select") {
17
state[opts.message.controlId] = opts.message.message.value;
18
}
19
20
renderControls();
21
});
22
23
function renderControls() {
24
const controls = [
25
canva.create("select", {
26
id: "selectExample",
27
value: state.selectExample,
28
options: [
29
{ value: "apples", label: "Apples" },
30
{ value: "bananas", label: "Bananas" },
31
{ value: "pears", label: "Pears" },
32
],
33
}),
34
];
35
36
canva.updateControlPanel(controls);
37
}
Copied!
Last modified 3d ago