For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Resources
Get started
ReferenceGuidesExamplesChangelog
ReferenceGuidesExamplesChangelog
  • Designer API
    • Introduction
    • Getting Started
    • Webflow CLI
    • Error Handling
    • App Modes
  • Elements
    • Creating & Retrieving Elements
    • Element Properties & Methods
    • Element Types & Methods
  • Styles
    • Managing Style Properties
    • Managing Variable Modes
  • Components
      • Get all components
      • Get component by name
      • Get component by ID
      • Search for components
      • Get the selected component
      • Get all variants of a component
      • Get selected variant
      • Get a variant by ID
      • Create a variant
      • Set variant settings
      • Reorder variants
      • Delete a variant
      • Get component instance count
      • Create a component
      • Delete a component
  • Variables & Collections
    • Variable Collections
    • Variables
    • Variable Modes
  • Assets
  • Pages & Folders
  • Utilities
    • User Events & Notifications
    • App Intents & Connections
  • Additional Resources
    • API Playground
    • FAQs
LogoLogo
Resources
Get started
On this page
  • component.getSelectedVariant()
  • Syntax
  • Returns
  • Example
  • Designer Ability
ComponentsCreating & Retrieving Components

Get selected variant (Beta)

Was this page helpful?
Previous

Get a variant by ID (Beta)

Next
Built with

component.getSelectedVariant()

Retrieves the selected variant of a component.

If no variant is selected (that is, with the isSelected attribute set to true), the function returns the base variant of the specified component. Similarly, if the currently selected component in the Designer is not a variant of the specified component, no variant of the specified component is selected, so the function returns the base variant of the specified component.

Beta

These methods are in public beta and may change with future releases.

Syntax

1component.getSelectedVariant(): Promise<Variant>

Returns

Promise<Variant>

A promise that returns a variant.

Example

1const selectedVariant = await heroComponent.getSelectedVariant();
2/*
3{
4 id: 'variant-123',
5 name: 'Secondary Hero',
6 isSelected: true,
7}
8*/
9// When no variant is explicitly selected, returns base
10const base = await heroComponent.getSelectedVariant();
11/*
12{
13 id: 'base',
14 name: 'Primary',
15 isSelected: true,
16}
17*/

Try this example


Designer Ability

Checks for authorization only

Designer AbilityPermissionLocaleBranchWorkflowSitemode
canAccessCanvasanyanyanyanyany