Sub topic 3
Declaring input and output properties in meta.xml
This chapter assumes you can write a basic LWC with @api properties and that you know how to build a screen flow with variables. You will declare which values a component accepts from a flow and which values it returns.
Why meta.xml controls the flow contract
A flow cannot see your JavaScript. Flow Builder reads only the .js-meta.xml file in the component bundle. A property that has an @api decorator in JavaScript but no <property> entry in the XML does not appear in Flow Builder. The XML is the contract, and the JavaScript must match it.
Declare properties inside a targetConfig element that applies to the lightning__FlowScreen target.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Quantity Picker</masterLabel>
<targets>
<target>lightning__FlowScreen</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__FlowScreen">
<property name="label" type="String" role="inputOnly" label="Field label" default="Quantity"/>
<property name="quantity" type="Integer" label="Quantity"/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>The targets attribute on targetConfig must name lightning__FlowScreen. Without it, the properties are not attached to flow screens.
Attributes of a property element
| Attribute | Purpose |
|---|---|
| `name` | Must match the `@api` property name in JavaScript exactly, including case. |
| `type` | The flow data type, such as `String`, `Integer`, `Boolean`, `Date`, or `DateTime`. |
| `label` | The text shown for the property in Flow Builder. |
| `description` | Help text shown next to the property. |
| `default` | The initial value when the builder does not set one. |
| `role` | Restricts direction: `inputOnly` or `outputOnly`. |
| `required` | Forces the builder to supply a value. |
Input, output, or both
If you leave out role, the property is both an input and an output. Flow Builder shows it as a field the builder can set, and as a value the builder can read after the screen.
role="inputOnly": the flow sets the value and cannot read it back. Thelabelproperty above works this way.role="outputOnly": the component sets the value and the flow reads it. The builder cannot assign a value.- No role: the flow passes a value in, and the component can send a changed value back out. The
quantityproperty above works this way.
Use inputOnly for configuration such as labels and limits. Use outputOnly for results the user did not receive from the flow, such as a selected record. Use both directions for a value the flow pre-fills and the user can edit.
Matching the JavaScript
Each <property> needs a public @api field of the same name.
import { LightningElement, api } from 'lwc';
export default class QuantityPicker extends LightningElement {
@api label = 'Quantity';
@api quantity;
}The default in the XML sets what Flow Builder shows. The default in JavaScript applies when the component runs without a value from the flow. Keep both the same to avoid confusing behavior.
The @api field receives values. It does not send them back on its own. Changing this.quantity inside the component updates the display, but the flow still holds the old value. The next chapters cover how to report changes with FlowAttributeChangeEvent.
Common mistakes
- A name mismatch between XML and JavaScript. The property appears in Flow Builder but never receives a value.
- Forgetting
targets="lightning__FlowScreen"ontargetConfig. The properties do not show up. - Marking a property
inputOnlyand then trying to send it back. The flow ignores the value. - Deploying XML changes without refreshing Flow Builder. Reload the flow to see new properties.
Exercise
A component needs a maxLength setting that the flow builder chooses, and a selectedId result that the flow reads after the screen. What role should each property have?
Show answer
maxLength should use role="inputOnly", because the flow supplies it and never reads it back. selectedId should use role="outputOnly", because the component produces it and the flow only reads it.
Exercise
You add <property name="Quantity" type="Integer"/> to the meta.xml, but the JavaScript declares @api quantity;. The field appears in Flow Builder. Why does the component never receive the value?
Show answer
The names differ in case. Quantity does not match quantity, so the flow value is not assigned to the JavaScript field. Make both names identical.