Overview
ThemiscModal and myModal components demonstrate how to create modal dialogs using the lightning/modal base component. Modals overlay content on the current app window and can return values when closed.
Source Components
- miscModal - Parent component that opens the modal
- myModal - Custom modal component that extends LightningModal
Key Features
- Programmatic modal creation
- Customizable size and content
- Return values on close
- ARIA accessibility support
Implementation
Creating the Modal Component
ExtendLightningModal and use the modal composition components:
Opening the Modal
Import and call theopen() method with configuration:
Modal Configuration
Theopen() method accepts these options:
- size - Modal size:
small,medium, orlarge - description - Accessibility description
- Custom properties (like
header,content) are passed to@apiproperties
The modal returns a Promise that resolves when closed. If closed with the X button, the promise returns
undefined. If closed programmatically with this.close(value), it returns the provided value.Return Values
Handle different close scenarios:Accessibility
Thearia-haspopup="true" attribute should be added to the button that opens the modal:
Source Files
force-app/main/default/lwc/miscModal/force-app/main/default/lwc/myModal/
