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

Usage

1
canva.create("slider", {
2
id: "sliderExample",
3
label: "Slider Example",
4
value: 50,
5
min: 0,
6
max: 100,
7
step: 1,
8
});
Copied!

Parameters

Name
Type
Required
Description
controlType
string
Yes
The type of control. To create a slider, the value must be "slider".
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.value
string
Yes
The value of the slider. This number must be within the range of the min and max properties.
opts.min
string
Yes
The minimum allowed value of the slider. This number can be an integer or a floating point number. It can also be negative or positive.
opts.max
string
Yes
The maximum allowed value of the slider. This number can be an integer or a floating point number. It can also be negative or positive.
opts.step
string
Yes
The number to increment or decrement by as a user adjusts the value of the slider. This number can be an integer or a floating point number.
opts.disabled
boolean
No
If true, the user can't interact with 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
If false, the user is actively interacting with the control. If true, the user has finished interacting with the control.
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 "slider".
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
number
Yes
The value of the slider.

Example

1
const canva = window.canva.init();
2
3
const state = {
4
sliderExample: 50,
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 === "slider") {
17
state[opts.message.controlId] = opts.message.message.value;
18
}
19
20
renderControls();
21
});
22
23
function renderControls() {
24
const controls = [
25
canva.create("slider", {
26
id: "sliderExample",
27
label: "Slider Example",
28
value: state.sliderExample,
29
min: 0,
30
max: 100,
31
step: 1,
32
}),
33
];
34
35
canva.updateControlPanel(controls);
36
}
Copied!
Last modified 3d ago