TextInput
API reference for the "TextInput" control.
Renders an input field within the Canva UI.
To learn how controls work, refer to Rich controls.

Usage

1
canva.create("text_input", {
2
inputType: "text",
3
id: "textInputExample",
4
placeholder: "Enter some text...",
5
label: "Text Input Example",
6
name: "textInputExample",
7
disabled: false,
8
value: "Hello world",
9
maxLength: 50,
10
});
Copied!

Parameters

Name
Type
Required
Description
controlType
string
Yes
The type of control. To create a text input, the value must be "text_input".
opts
object
Yes
Properties for configuring the control.
opts.id
string
Yes
A unique ID for the control.
opts.inputType
string
Yes
The type of input. The possible values are "text" and "number".
opts.disabled
boolean
No
If true, the text input is disabled. The default value is false.
opts.label
string
No
A human readable label for the control.
opts.maxLength
number
No
The maximum number of characters allowed in the input. This property is only valid when the inputType is "text".
opts.name
string
No
opts.placeholder
string
No
A human readable prompt that's displayed when the value property is empty.
opts.value
string
No
The value of the text input.

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 "text_input".
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 "change".
opts.message.message.value
string | number
Yes
The value of the input.

Example

1
const canva = window.canva.init();
2
3
const state = {
4
textInputExample: "Hello world",
5
numberInputExample: 42,
6
};
7
8
canva.onReady(() => {
9
renderControls();
10
});
11
12
canva.onControlsEvent(async (opts) => {
13
if (!opts.message.commit) {
14
return;
15
}
16
17
if (opts.message.controlType === "text_input") {
18
state[opts.message.controlId] = opts.message.message.value;
19
}
20
21
renderControls();
22
});
23
24
function renderControls() {
25
const controls = [
26
canva.create("text_input", {
27
inputType: "text",
28
id: "textInputExample",
29
placeholder: "Enter some text...",
30
label: "Text Input Example",
31
disabled: false,
32
value: state.textInputExample,
33
maxLength: 50,
34
}),
35
canva.create("text_input", {
36
inputType: "number",
37
id: "numberInputExample",
38
placeholder: "Enter a number...",
39
label: "Number Input Example",
40
disabled: false,
41
value: state.numberInputExample,
42
}),
43
];
44
45
canva.updateControlPanel(controls);
46
}
Copied!
Last modified 3d ago