Registers a callback that runs when a user selects (or deselects) an element containing a specific type of content.
To learn more, see:
Usage
import { selection } from "@canva/design";await selection.registerOnChange({scope: "text",onChange: (event) => {console.log(event);},});
Permissions
Before an app that uses this method can be submitted for review, the following permissions must be enabled via the Developer Portal:
canva:design:content:read
, if the app calls theread
methodcanva:design:content:write
, if the app calls thesave
method
To learn more, see Configuring permissions.
Parameters
The options for registering an element selection callback.
The type of content that should trigger a selection event.
The available options include:
"image"
"text"
The callback that runs when a user selects or deselects an element that contains the specified type of content.
The selection event.
The type of content that's selected. This is determined by the scope
passed in the options
object.
The number of selected elements.
A function that returns:
- An array of the selected elements
- A method for persisting changes to those elements
The content of the selected elements. Each element is represented as an object. To modify the content of those elements: loop through the elements, mutate their properties, and call the save
method.
If the scope
property is "image"
, each object has the following properties:
ref
- An identifier that points to an image asset in Canva's backend.
If the scope
property is "text"
, each object has the following properties:
text
- The text content of the element, as plain text.
Saves any changes made to the contents
array and updates the user's design to reflect those changes.
Returns
Promise<void>