Sub topic 3
Naming the Component for Admins: masterLabel and description
This chapter covers two elements in the js-meta.xml file that control how admins see your component: masterLabel and description. It assumes you can read a basic Lightning web component bundle (HTML template, JavaScript class, metadata file) and that you can follow XML. It also assumes you know your way around the Setup UI and Lightning pages, and can deploy to an org with Salesforce CLI.
Why the name matters
A developer finds a component by its folder name, such as accountSummaryCard. An admin never sees that name in App Builder. The admin sees a label in the Components list, in the search box, and in the page canvas. If you don't set a label, App Builder falls back to the bundle name. That name is camelCase and carries no spaces, so it reads poorly in a list of standard components.
Two elements fix this:
masterLabelis the display name admins see.descriptionis a short explanation of what the component does.
Neither element changes how the component runs. Both only change how it is presented.
The masterLabel element
masterLabel sets the label shown in the App Builder Components panel. It also appears as the title of the component's property panel when the admin selects it on the canvas.
<?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>
<description>Shows a titled card with the current record context.</description>
<targets>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__RecordPage</target>
</targets>
</LightningComponentBundle>Here the bundle is named accountSummaryCard. With the masterLabel above, admins see Account Summary Card instead.
Behavior when masterLabel is missing
masterLabel is optional. If you leave it out, App Builder shows the bundle name. The component still works, but the label looks unpolished. Treat masterLabel as required for any component an admin will use.
What changes and what does not
The label is a display value only. Other code and metadata refer to the component by its bundle name:
- A parent component uses
<c-account-summary-card>. - A Lightning page that already contains the component stores a reference to the bundle name.
sf project deploy start --source-dirtakes the folder path.
Because of this, you can change masterLabel at any time without breaking existing pages. Renaming the folder is a different matter. It creates a different component and can break pages that use the old one.
Choosing a good label
Admins scan a list that may hold dozens of components, including standard ones. Follow these habits:
- Use words an admin would search for. "Account Summary Card" is better than "ASC Component v2".
- Use title case with spaces, matching the style of standard components.
- Describe what it shows or does, not how it is built. "Open Cases List" beats "Case Wire Datatable".
- Keep it short enough to read in a narrow panel. About 40 characters is a practical upper limit.
- Don't put "LWC" or "Lightning" in the name. Every component in the list is one.
- Don't put version numbers in the label. Version information belongs in source control.
The description element
description is a one-sentence summary of the component. App Builder doesn't show it in every view. It is most useful for admins who browse custom components in Setup and for developers who read the metadata later. Write it anyway, because a clear description tells the next person what the component is for and where it fits.
Good descriptions share a few traits:
- They start with a verb or a noun phrase, not "This component...".
- They state what the admin gets, such as "Shows a titled card with the current record context."
- They mention a limit when one exists, such as "Account record pages only."
- They stay under one or two sentences.
Compare these two:
| Weak description | Stronger description |
|---|---|
| A component. | Shows a titled card with the current record context. |
| LWC for accounts. | Lists the five most recent open cases for an account. Use on Account record pages. |
| Test | Displays a configurable banner with a header and a link on app and home pages. |
Keeping description in step with targets
If you restrict a component to certain pages or objects (covered in later chapters), the description is the best place to say so in plain words. An admin who sees "Account record pages only" understands at once why the component is missing from a Case page.
Where each value appears
| Element | Where admins see it | If omitted |
|---|---|---|
| `masterLabel` | Components panel, search results, property panel title | Bundle name is shown |
| `description` | Custom component details and metadata views | No summary is shown |
Where exactly these values appear can vary a little between releases, so check your own org. Deploy a test component and look at the Components panel for the label. The exact placement of the description matters less than writing it well.
How the elements fit in the file
The XML schema for LightningComponentBundle doesn't require a particular order for most elements, but the convention is to group identity first and behavior after. A readable layout looks like this:
apiVersionisExposedmasterLabeldescriptiontargetstargetConfigs
Following one order across all your components makes reviews faster. A reviewer can then find the label and description in the same place in every file.
Common errors
These problems come up often with labels and descriptions.
- The label looks like code. You left out
masterLabel, so the bundle name shows. Add the element and redeploy. - The label did not change after editing. The new metadata has not been deployed, or the admin's browser has the old component list cached. Redeploy, then refresh the App Builder page.
- XML fails to deploy because of special characters. An ampersand in a label, such as
Cases & Tasks, is invalid XML. WriteCases & Tasks, or avoid the character. - Two components share the same label. Admins can't tell them apart in the list. Make each label unique, or add a short qualifier, such as "Case List (Compact)".
- A label promises more than the component delivers. "Customer 360" for a card that shows three fields misleads admins. Name it for what it does.
- The element is in the wrong place.
masterLabelanddescriptionbelong directly underLightningComponentBundle. Nesting them insidetargetConfighas no effect, and the deploy can fail.
Checking your work
Deploy the bundle, then confirm the label from the command line before opening App Builder. This command deploys the component:
sf project deploy start --source-dir force-app/main/default/lwc/accountSummaryCardAfter it succeeds, open a Lightning page in App Builder and search the Components panel for the label text. If the component appears under its readable name, masterLabel is working. If it appears under the bundle name, check that the element is spelled exactly masterLabel (case matters) and that the file you edited is the one that was deployed.
Design decisions
Some choices come up when you build a component library.
- Short label or descriptive label. A short label scans faster. A longer one distinguishes similar components. Choose the shortest label that is still unique in your org.
- Naming a family of components. If you build several related components, share a prefix or suffix, such as "Case List" and "Case Detail". Admins then find the group by searching for one word.
- Managed packages. If you ship components in a package, your label sits next to the labels of other vendors. A clear label matters even more, because admins can't read your source.
- Translations.
masterLabelis a single text value in the metadata file. If you need labels in several languages, check current Salesforce documentation for the supported approach in your release. Don't assume the XML text translates itself.
Summary of the rules
- Set
masterLabelon every exposed component. It is optional in the schema but expected in practice. - Write
descriptionas a short, specific sentence. - Treat both as presentation. They don't affect behavior and don't change how other code refers to the component.
- Escape XML special characters.
- Verify in App Builder after each deploy.
Exercise
A teammate deploys a component whose folder is openCasesList. In App Builder it shows up as "openCasesList", and the Components panel has no helpful summary. Which two elements should they add to the metadata file, and where do those elements go? Also, will adding them break pages that already use the component?
Show answer
They should add masterLabel (for example, Open Cases List) and description (for example, Lists the open cases for the current account. Use on Account record pages.). Both go directly under the LightningComponentBundle element, alongside apiVersion and isExposed, not inside targetConfig. Adding them will not break existing pages, because pages reference the bundle name openCasesList, and the label is only a display value.
Exercise
This masterLabel fails to deploy: <masterLabel>Cases & Tasks</masterLabel>. What is wrong, and how do you fix it?
Show answer
The ampersand is a reserved character in XML, so the file is not valid. Escape it as &, giving <masterLabel>Cases & Tasks</masterLabel>, or rename the component to avoid the character, for example "Cases and Tasks".