Component Visibility
Overview
Instead of always showing all components, you can define rules that determine when a component is visible. Show a section only when a checkbox is checked, hide a chart on mobile, or display a form only after the user picks an option.
Visibility rules work on Lightning Pages and Experience Cloud sites (both Aura and LWR). The conditions you define in the Component Builder apply at runtime regardless of where the Dynamic Component is deployed.
Info
If you're building on an Experience Cloud site and find that Salesforce Audiences are too broad for your needs, visibility rules give you field-level and interaction-level control over what appears on the page. See Experience Sites Integration for setup details.
How Dynamic Visibility Works
Every Avonni component has a Set Component Visible property (in the Properties Panel) that controls its display. You can set it to:
Always Visible (
true): The default; the component is always shown.Always Hidden (
false): The component is never shown.Conditional Visibility: The component is shown only when specific conditions are met.

Setting Up Conditional Visibility
To make a component's visibility conditional:
Select the Component: Click on the component in the canvas whose visibility you want to control.
Find the "Set Component Visibility" Property: In the Properties Panel (right side), locate the
Visibleproperty.Click the Resource Selector: Click the icon next to the
Visibleproperty (usually a variable/tag icon). This opens the resource selection menu. Do not simply typetrueorfalseunless you want the component to be always visible or always hidden.Choose your condition:
Component Attribute: Base visibility on the state or value of another component (e.g., show Component B only if
@MyCheckbox.checkedis true).Variable: Use a Boolean Variable resource you created. The component shows when the variable is
true.Formula: Use a Formula resource that evaluates to
true(visible) orfalse(hidden). Allows complex logic.Global Variable: Use system-provided information.
New: For Device Type: Select
$Component, then choose theFormFactorattribute. This holds the current device type as text:'Desktop','Tablet', or'Phone'.
Examples
Conditionally Displaying a Calendar
Let's create an example in which an Avonni Calendar component is visible only when the user selects the "Calendar" option from an Avonni Button Menu.
Set the Calendar's Visibility
Select the Calendar component.
In the Properties Panel, find the
Visibleproperty.Click the resource selector icon.
Select
Component Attribute.Select your Button Menu component (e.g.,
ViewModeMenu).Choose the
valueattribute.Set the operator to
equalsSet the value to
calendar.

How It Works
The Calendar's Visible property is now directly linked to the value of the ViewModeMenu Button Menu. When the user selects "Calendar" in the Button Menu, the value becomes 'calendar', the condition evaluates to true, and the Calendar component is displayed. If any other option is selected, the condition is false, and the Calendar is not loaded.
Device-Specific Layout
Let's show a detailed Data Table on desktops/tablets, but a simpler List component on phones.
Add Data Table
Add your Data Table component (e.g., MyDataTable).
Set Data Table Visibility
Select
MyDataTable.In the
Visibleproperty, set the condition: Global Variable$Component.FormFactornot equal to'Phone'.
Add List Component
Add your List component (e.g., MyList) designed for mobile viewing.
Set List Visibility
Select
MyList.In the
Visibleproperty, set the condition: Global Variable$Component.FormFactorequals'Phone'.

Result: Users on desktops or tablets will see the Data Table, while users viewing on a phone will see the List component, providing an optimized view for each device form factor.
Common Use Cases
Conditional Forms: Show/hide form fields based on previous selections.
Personalized Dashboards: Display different components based on user role or profile.
Progressive Disclosure: Gradually reveal information as the user interacts.
Error Messages: Show error messages only when an error occurs.
Loading Indicators: Show a loading indicator while data is being fetched, then hide it and show the data component.
Creating Responsive Layouts that adapt to Desktop, Tablet, and Phone screens
Experience Cloud sites: Control component visibility based on record data or user interactions when Salesforce Audiences don't offer enough granularity. For example, show a Flow only to users whose Account has a specific
Typevalue, or hide a section until the user selects a tab. This works on both Aura and LWR sites.
Tips
Start Simple: Begin with simple conditions and gradually increase complexity.
Test Thoroughly: Test your visibility conditions with different data and user interactions.
Use Formulas Carefully: While powerful, complex formulas can be more complicated to maintain.
Use Boolean Variables: Create boolean variables to make it more readable.
In Summary
Link the Visible property to data, component attributes, formulas, or $Component.FormFactor to control when components appear. This works on Lightning Pages and Experience Cloud sites alike. In Experience Cloud, visibility rules provide the fine-grained, condition-based control that Salesforce Audiences doesn't cover.
Last updated
Was this helpful?
