Sub topic 11
Supported form factors for desktop and phone
This chapter assumes you have a component with a working .js-meta.xml file, isExposed set to true, and at least one target. It shows how to control whether App Builder offers the component on desktop pages, phone pages, or both.
What a form factor is
A form factor is the kind of device a Lightning page is built for. The metadata API gives you two values:
| Value | Devices | Where it applies |
|---|---|---|
| `Large` | Desktop and tablet | Pages viewed in a wide browser window |
| `Small` | Phone | Pages viewed in the Salesforce mobile app |
An admin picks a form factor when they work on a page. App Builder then lists only the components that support it. A component can be exposed and have a valid target but still be missing from the list because it does not declare the form factor the admin is using.
Declaring supported form factors
You declare form factors with a supportedFormFactors element inside a targetConfig. Each supportedFormFactor child names one value.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Account Summary Card</masterLabel>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__AppPage,lightning__HomePage">
<property name="headerText" type="String" label="Header text" default="Summary" />
<supportedFormFactors>
<supportedFormFactor type="Large" />
</supportedFormFactors>
</targetConfig>
<targetConfig targets="lightning__RecordPage">
<objects>
<object>Account</object>
</objects>
<property name="headerText" type="String" label="Header text" default="Summary" />
<supportedFormFactors>
<supportedFormFactor type="Large" />
<supportedFormFactor type="Small" />
</supportedFormFactors>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>In this file the component is desktop-only on app and home pages. On Account record pages it is available on desktop and phone.
Because form factors live inside targetConfig, you set them per target group. That lets you offer a phone version on one page type and not on another.
What happens when you leave it out
If a targetConfig has no supportedFormFactors element, App Builder treats the component as desktop-only (Large). To make a component appear on phone pages, you must add Small explicitly.
Design the component for the form factor you declare
Declaring Small only makes the component selectable. It does not make the layout responsive. Before you add Small, check these points:
- Use SLDS grid classes or layout components that stack on narrow screens, not fixed pixel widths.
- Keep the content short. A phone shows one column, so long tables and wide cards need a different design.
- Test on the Salesforce mobile app or in a phone preview, not only in a desktop browser.
If the component cannot work well on a phone, leave Small out. Admins then cannot place it on a phone page by mistake.
Deploy and check
Deploy the bundle as before:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardThen open an Account record page in App Builder. Check that the component appears under Custom components. Switch to a phone-based page and confirm that it appears only where you declared Small.
Exercise
Your component is exposed on lightning__RecordPage with an objects restriction to Account. The targetConfig has no supportedFormFactors element. An admin building a phone record page for Account cannot find the component. What change fixes this, and where does it go?
Show answer
Add a supportedFormFactors element containing <supportedFormFactor type="Small" /> inside the targetConfig for lightning__RecordPage. Keep Large as well if desktop pages should still list the component. Without the element, the component is treated as desktop-only. Redeploy the bundle afterward.