Introduction

Important:

  • This module is available only in Wix Blocks. Wix Blocks is an editor for building Wix apps.
  • This module doesn't work in preview mode.

The wix-widget API is used within the code of panels built with the Blocks Panel Builder. It enables your panel to interact with your Blocks widgets by controlling their properties, design presets, and more.
To use this API, import wixWidget from the wix-widget module:

Copy
Did this help?

getDesignPreset( )


Gets the widget's current design preset.

The getDesignPreset() function returns a Promise that resolves to the widget's current preset name. To use this function on an inner (nested) widget, use getNestedWidget().

Note: The getDesignPreset() function doesn't work in preview mode.

Method Declaration
Copy
Request
This method does not take any parameters
Returns
Return Type:Promise<string>
Get a widget's design preset
JavaScript
Did this help?

getNestedWidget( )


Gets the wix-widget module scoped to an inner (nested) widget.

The getNestedWidget() function lets you use wix-widget functions on inner (nested) widgets. It receives a selector of an inner widget and returns a promise that resolves with an object representing the scope of the inner widget.

Note: The getNestedWidget() function doesn't work in preview mode.

Method Declaration
Copy
Method Parameters
SelectorstringRequired

A string of one or more nested widget selectors, which can include a few levels of nesting from outer to inner, separated by spaces. For example: ("#nestedWidget1"), or ("#nestedWidget1 #nestedWidget2").

Returns
Return Type:Promise<object>
Get a nested widget's preset
JavaScript
Did this help?

getProps( )


Gets the widget's properties.

The getProps() function returns a Promise that resolves to an object with all of the widget's properties. To use this function on an inner (nested) widget, use getNestedWidget().

Note: The getProps() function doesn't work in preview mode.

Method Declaration
Copy
Request
This method does not take any parameters
Returns
Return Type:Promise<object>
Get a widget's properties
JavaScript
Did this help?

setDesignPreset( )


Sets the widget's design preset.

The setDesignPreset() function returns a Promise that resolves when the design preset is set. To use this function on an inner (nested) widget, use getNestedWidget().

Note: The setDesignPreset() function doesn't work in preview mode.

Method Declaration
Copy
Method Parameters
presetstringRequired

Preset name.

Set a widget's design preset
JavaScript
Did this help?

setProps( )


Sets the widget's properties. You can also assign a partial subset of the widget's properties.

The setProps() function returns a Promise that resolves when the properties are set. To use this function on an inner (nested) widget, use getNestedWidget().

Note: The setProps() function doesn't work in preview mode.

Method Declaration
Copy
function setProps(props: object): Promise<void>;
Method Parameters
propsPropsRequired

Object with some or all of the widget's properties.

Set a widget's properties
JavaScript
import wixWidget from "wix-widget"; // ... wixWidget.setProps({ saleIndicator: "No Sale" }).then(() => { // Code to execture after setting the props });
Did this help?