Sub topic 6
Laying out the panel with lightning-quick-action-panel
This chapter covers the markup of a screen action: how lightning-quick-action-panel structures the modal, what goes in the footer slot, and which layout mistakes cause trouble. It assumes you can read an LWC template and know what @api, event handlers, and js-meta.xml do. Exposing the component as an action and saving data are covered in other chapters. They appear here only where they affect layout.
What the panel gives you
When a user clicks a screen action, Salesforce opens a modal dialog and renders your component inside it. The platform supplies the modal frame, the close (X) button, and the backdrop. It does not supply a header, body styling, or a footer. lightning-quick-action-panel supplies those, so your action looks like the standard actions on the record page.
The component has three parts:
- A
headerattribute. It holds the title text shown at the top of the modal. - A default slot. Everything you place directly inside the tag becomes the body.
- A named slot,
footer. Content withslot="footer"is placed in the bottom bar of the modal, usually where the Cancel and Save buttons go.
A complete template
This template belongs to the updateDescription component used in this tutorial. It shows all three parts.
<template>
<lightning-quick-action-panel header="Update Description">
<lightning-textarea
label="Description"
value={description}
onchange={handleChange}>
</lightning-textarea>
<div slot="footer">
<lightning-button variant="neutral" label="Cancel" onclick={handleCancel}></lightning-button>
<lightning-button variant="brand" label="Save" onclick={handleSave} disabled={isSaving}></lightning-button>
</div>
</lightning-quick-action-panel>
</template>Three details are worth noting.
- The
lightning-textareahas no slot attribute, so it goes into the default slot and becomes the body. - The
divwithslot="footer"is moved into the footer area. Its position inside the panel tag does not matter. You could write it first and it would still render at the bottom. - The Save button has
disabled={isSaving}. The class setsisSavingtotruewhileupdateRecordruns. This stops a second click from starting a duplicate save.
The header
header is a plain string attribute. Use a short label that names the task, such as "Update Description" or "Log a Call". The header is not a place for record data or long instructions.
If the title depends on data, bind it to a getter instead of a literal:
<template>
<lightning-quick-action-panel header={panelTitle}>
<p>Review the changes before you continue.</p>
</lightning-quick-action-panel>
</template>import { LightningElement, api } from 'lwc';
export default class ReviewPanel extends LightningElement {
@api recordId;
@api objectApiName;
get panelTitle() {
return this.objectApiName === 'Account'
? 'Review Account'
: 'Review Record';
}
}objectApiName is passed to record actions in the same way as recordId. Neither value is guaranteed to be set during the constructor, so read them in a getter or after the component connects, not in field initializers.
The body
The default slot accepts any markup. Common choices are:
lightning-textarea,lightning-input, andlightning-comboboxfor single fields.lightning-record-edit-formwithlightning-input-fieldwhen you want the platform to render fields that respect field-level security and page layout rules.- Plain text and
lightning-formatted-textfor confirmation prompts. - A
lightning-spinnerwhile data loads.
The body scrolls when it grows taller than the modal. You do not need to set heights yourself. Fixed heights and overflow rules on the body often cause double scrollbars, so leave them out.
Showing a loading state
A spinner needs a positioned parent. Wrap the body content in a div with the slds-is-relative class so the spinner covers only the body and not the whole modal:
<template>
<lightning-quick-action-panel header="Update Description">
<div class="slds-is-relative">
<lightning-spinner
if:true={isSaving}
alternative-text="Saving"
size="small">
</lightning-spinner>
<lightning-textarea
label="Description"
value={description}
onchange={handleChange}>
</lightning-textarea>
</div>
<div slot="footer">
<lightning-button variant="neutral" label="Cancel" onclick={handleCancel}></lightning-button>
<lightning-button variant="brand" label="Save" onclick={handleSave} disabled={isSaving}></lightning-button>
</div>
</lightning-quick-action-panel>
</template>The footer
The footer slot is for actions that finish or abandon the task. Follow the usual Salesforce convention:
- Cancel is the
neutralvariant and sits on the left. - Save, or the main action, is the
brandvariant and sits on the right. - Do not add a third prominent button. If you need one, the action is probably doing too much.
Buttons in the footer are normal LWC elements. They can call any handler in your class. The panel does not close by itself when a footer button is clicked. Your handler must dispatch CloseActionScreenEvent, which a later chapter covers.
If the action has nothing to submit, such as a read-only information panel, you can leave out the footer slot. The modal still has its X button for closing.
Panel or custom layout
You are not required to use the panel. A screen action is an ordinary component, so you could write your own header and footer with SLDS classes. The table compares the two choices.
| Concern | `lightning-quick-action-panel` | Custom SLDS markup |
|---|---|---|
| Matches standard action styling | Yes, automatically | Only if you copy the classes correctly |
| Follows future platform styling changes | Yes | No |
| Control over header content | A string only | Anything |
| Effort | A few lines | Many lines, plus testing in each theme |
Use the panel unless you need a header with icons or custom elements. For most actions that need is rare.
Edge cases and common mistakes
- Using the panel in a headless action. A headless action has no UI. The panel has nothing to render, and the component only needs an
invoke()method. - Using the panel outside an action. It is designed for the quick action modal. In a record page region or an app page it does not give a usable layout.
- Putting the footer outside the panel. An element with
slot="footer"that is not a direct child oflightning-quick-action-panelis not placed in the footer. Keep it as a direct child, not nested inside anotherdiv. - Nesting a second modal. Do not open a
lightning-modalor a custom modal from inside the panel. Two stacked dialogs cause focus and scrolling problems. Put the extra step in the body instead, for example withif:truetoggling a confirmation view. - Relying on the panel for sizing. Quick action modals have a fixed width set by the platform. Wide tables or long inputs wrap or scroll. Design the body for a narrow column.
- Forgetting disabled state. Without
disabled={isSaving}or similar, double clicks can send two saves.
Switching between steps inside one panel
A simple two-step flow, such as "edit" then "confirm", can live in one panel. Change the header and footer based on a state property:
<template>
<lightning-quick-action-panel header={panelTitle}>
<template if:true={isEditing}>
<lightning-textarea
label="Description"
value={description}
onchange={handleChange}>
</lightning-textarea>
</template>
<template if:false={isEditing}>
<p>Save this description?</p>
<p>{description}</p>
</template>
<div slot="footer">
<lightning-button variant="neutral" label={secondaryLabel} onclick={handleSecondary}></lightning-button>
<lightning-button variant="brand" label={primaryLabel} onclick={handlePrimary}></lightning-button>
</div>
</lightning-quick-action-panel>
</template>import { LightningElement, api } from 'lwc';
import { CloseActionScreenEvent } from 'lightning/actions';
export default class TwoStepPanel extends LightningElement {
@api recordId;
description = '';
isEditing = true;
get panelTitle() {
return this.isEditing ? 'Edit Description' : 'Confirm Description';
}
get primaryLabel() {
return this.isEditing ? 'Next' : 'Save';
}
get secondaryLabel() {
return this.isEditing ? 'Cancel' : 'Back';
}
handleChange(event) {
this.description = event.target.value;
}
handlePrimary() {
if (this.isEditing) {
this.isEditing = false;
} else {
// Save logic goes here. See the chapter on updateRecord.
this.dispatchEvent(new CloseActionScreenEvent());
}
}
handleSecondary() {
if (this.isEditing) {
this.dispatchEvent(new CloseActionScreenEvent());
} else {
this.isEditing = true;
}
}
}The footer stays a direct child of the panel in both states. Only the labels and handlers change. Keeping one footer avoids the slot problem described in the warning above.
Summary of the layout rules
- Put the title in
header. - Put the main content directly inside the panel tag.
- Put buttons in a direct child with
slot="footer". - Use
neutralfor Cancel andbrandfor the main action. - Disable the main button while a save is running.
- Close the panel from your own code, because the panel never closes itself.
Exercise
A developer wraps the Cancel and Save buttons in a div with class="footer-wrapper", then puts slot="footer" on a div inside that wrapper. The buttons show up directly under the textarea instead of in the footer bar. What is wrong, and how do you fix it?
Show answer
The element with slot="footer" is not a direct child of lightning-quick-action-panel, so the panel cannot place it in the footer slot and it falls into the body. Move the slot="footer" attribute onto the outer div, or remove the wrapper so the slotted div is a direct child. If you need the extra class for styling, put it on the same element that carries slot="footer".
Exercise
Why does the updateDescription Save button use disabled={isSaving}, and where in the class is isSaving changed?
Show answer
It prevents a second click from starting a duplicate updateRecord call while the first is still running. The handleSave method sets isSaving to true before the call, and a finally block sets it back to false once the call succeeds or fails.