lightning-base-components 1.16.3-alpha → 1.16.4-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/metadata/raptor.json +106 -0
  2. package/package.json +57 -1
  3. package/scopedImports/@salesforce-label-LightningForm.cancel.js +1 -0
  4. package/scopedImports/@salesforce-label-LightningForm.closeError.js +1 -0
  5. package/scopedImports/@salesforce-label-LightningForm.edit.js +1 -0
  6. package/scopedImports/@salesforce-label-LightningForm.editErrorHelp.js +1 -0
  7. package/scopedImports/@salesforce-label-LightningForm.error.js +1 -0
  8. package/scopedImports/@salesforce-label-LightningForm.errorPopoverHeading.js +1 -0
  9. package/scopedImports/@salesforce-label-LightningForm.preview.js +1 -0
  10. package/scopedImports/@salesforce-label-LightningForm.previewHeader.js +1 -0
  11. package/scopedImports/@salesforce-label-LightningForm.reload.js +1 -0
  12. package/scopedImports/@salesforce-label-LightningForm.save.js +1 -0
  13. package/scopedImports/@salesforce-label-LightningForm.saveFieldErrorSummary.js +1 -0
  14. package/scopedImports/@salesforce-label-LightningForm.undo.js +1 -0
  15. package/scopedImports/@salesforce-label-LightningLookup.messageWhenMissingInformation.js +1 -0
  16. package/src/lightning/button/__docs__/button.md +13 -0
  17. package/src/lightning/button/button.slds.css +155 -11
  18. package/src/lightning/buttonGroup/button-group.slds.css +35 -59
  19. package/src/lightning/buttonIcon/button-icon.slds.css +287 -122
  20. package/src/lightning/buttonIconStateful/button-icon-stateful.slds.css +224 -39
  21. package/src/lightning/buttonStateful/button-stateful.slds.css +3269 -0
  22. package/src/lightning/card/card.slds.css +50 -0
  23. package/src/lightning/colorPickerCustom/color-picker-custom.slds.css +180 -364
  24. package/src/lightning/colorPickerPanel/color-picker-panel.slds.css +46 -413
  25. package/src/lightning/datatable/datatable.js +2 -2
  26. package/src/lightning/datatable/rowSelection.js +21 -4
  27. package/src/lightning/datetimepicker/datetimepicker.html +1 -3
  28. package/src/lightning/datetimepicker/datetimepicker.js +5 -0
  29. package/src/lightning/fileDownload/__docs__/fileDownload.md +41 -0
  30. package/src/lightning/helptext/help-text.slds.css +184 -39
  31. package/src/lightning/icon/icon.slds.css +823 -3
  32. package/src/lightning/input/input-checkbox.slds.css +291 -32
  33. package/src/lightning/input/input-text.slds.css +70 -7
  34. package/src/lightning/inputAddress/__docs__/inputAddress.md +1 -1
  35. package/src/lightning/inputAddress/inputAddress.js +2 -1
  36. package/src/lightning/internationalizationLibrary/datetime/intlFormat.js +20 -2
  37. package/src/lightning/iso8601Utils/iso8601Utils.js +2 -3
  38. package/src/lightning/modal/__docs__/migration.md +158 -0
  39. package/src/lightning/modal/__docs__/modal.md +414 -0
  40. package/src/lightning/modal/__examples__disabled/all/all.css +7 -0
  41. package/src/lightning/modal/__examples__disabled/all/all.html +9 -0
  42. package/src/lightning/modal/__examples__disabled/all/all.js +25 -0
  43. package/src/lightning/modal/__examples__disabled/allform/allform.css +7 -0
  44. package/src/lightning/modal/__examples__disabled/allform/allform.html +9 -0
  45. package/src/lightning/modal/__examples__disabled/allform/allform.js +49 -0
  46. package/src/lightning/modal/__examples__disabled/allmulti/allmulti.html +24 -0
  47. package/src/lightning/modal/__examples__disabled/allmulti/allmulti.js +12 -0
  48. package/src/lightning/modal/__examples__disabled/basic/basic.css +7 -0
  49. package/src/lightning/modal/__examples__disabled/basic/basic.html +9 -0
  50. package/src/lightning/modal/__examples__disabled/basic/basic.js +27 -0
  51. package/src/lightning/modal/__examples__disabled/demo/demo.html +15 -0
  52. package/src/lightning/modal/__examples__disabled/demo/demo.js +13 -0
  53. package/src/lightning/modal/__examples__disabled/demoall/demoall.html +26 -0
  54. package/src/lightning/modal/__examples__disabled/demoall/demoall.js +13 -0
  55. package/src/lightning/modal/__examples__disabled/demoallform/demoallform.css +3 -0
  56. package/src/lightning/modal/__examples__disabled/demoallform/demoallform.html +146 -0
  57. package/src/lightning/modal/__examples__disabled/demoallform/demoallform.js +240 -0
  58. package/src/lightning/modal/__examples__disabled/demofootless/demofootless.html +17 -0
  59. package/src/lightning/modal/__examples__disabled/demofootless/demofootless.js +11 -0
  60. package/src/lightning/modal/__examples__disabled/demoheadless/demoheadless.html +20 -0
  61. package/src/lightning/modal/__examples__disabled/demoheadless/demoheadless.js +12 -0
  62. package/src/lightning/modal/__examples__disabled/footless/footless.css +7 -0
  63. package/src/lightning/modal/__examples__disabled/footless/footless.html +9 -0
  64. package/src/lightning/modal/__examples__disabled/footless/footless.js +19 -0
  65. package/src/lightning/modal/__examples__disabled/headless/headless.css +7 -0
  66. package/src/lightning/modal/__examples__disabled/headless/headless.html +9 -0
  67. package/src/lightning/modal/__examples__disabled/headless/headless.js +27 -0
  68. package/src/lightning/modal/modal.html +3 -0
  69. package/src/lightning/modal/modal.js +93 -0
  70. package/src/lightning/modal/modal.js-meta.xml +6 -0
  71. package/src/lightning/modalBody/__docs__/modalBody.md +61 -0
  72. package/src/lightning/modalBody/modalBody.html +13 -0
  73. package/src/lightning/modalBody/modalBody.js +203 -0
  74. package/src/lightning/modalBody/modalBody.js-meta.xml +6 -0
  75. package/src/lightning/modalFooter/__docs__/modalFooter.md +72 -0
  76. package/src/lightning/modalFooter/modalFooter.html +8 -0
  77. package/src/lightning/modalFooter/modalFooter.js +161 -0
  78. package/src/lightning/modalFooter/modalFooter.js-meta.xml +6 -0
  79. package/src/lightning/modalHeader/__docs__/modalHeader.md +64 -0
  80. package/src/lightning/modalHeader/modalHeader.html +16 -0
  81. package/src/lightning/modalHeader/modalHeader.js +204 -0
  82. package/src/lightning/modalHeader/modalHeader.js-meta.xml +6 -0
  83. package/src/lightning/primitiveBubble/tooltip.slds.css +45 -1
  84. package/src/lightning/primitiveCellFactory/primitiveCellFactory.js +4 -12
  85. package/src/lightning/primitiveColorpickerButton/color-picker-button.slds.css +2994 -319
  86. package/src/lightning/primitiveDatatableIeditPanel/primitiveDatatableIeditPanel.html +14 -11
  87. package/src/lightning/primitiveDatatableIeditPanel/primitiveDatatableIeditPanel.js +1 -0
  88. package/src/lightning/primitiveIcon/icon.slds.css +823 -3
  89. package/src/lightning/radioGroup/input-radio-group.slds.css +168 -379
  90. package/src/lightning/spinner/spinner.slds.css +8 -2
  91. package/src/lightning/timepicker/timepicker.html +1 -4
  92. package/src/lightning/timepicker/timepicker.js +9 -5
  93. package/src/lightning/treeGrid/treeGrid.js +66 -1
  94. package/src/lightning/formattedAddress/__component__/formattedAddress.spec.js +0 -61
  95. package/src/lightning/formattedAddress/__component__/formattedAddressDisabled.spec.js +0 -20
  96. package/src/lightning/formattedAddress/__component__/x/basic/basic.html +0 -10
  97. package/src/lightning/formattedAddress/__component__/x/basic/basic.js +0 -17
  98. package/src/lightning/input/__component__/inputCheckbox.spec.js +0 -60
  99. package/src/lightning/input/__component__/inputDateTimePicker.spec.js +0 -60
  100. package/src/lightning/input/__component__/inputNumber.spec.js +0 -75
  101. package/src/lightning/input/__component__/inputSelection.spec.js +0 -83
  102. package/src/lightning/input/__component__/x/tall/tall.css +0 -5
  103. package/src/lightning/input/__component__/x/tall/tall.html +0 -5
  104. package/src/lightning/input/__component__/x/tall/tall.js +0 -7
@@ -0,0 +1,158 @@
1
+ # Migrating from Other Modal Solutions to LightningModal
2
+
3
+ This document is about migrating existing modal implementations.
4
+
5
+ ## **Creating a new LWC-based modal implementation?**
6
+ * Starting in release 236, when utilizing LWC or Aura code, your team should use `LightningModal`
7
+ * Dive into the details here by [Creating a Modal Component](modal.md#creating-a-modal-component)
8
+ * Or, take a look at some of our [Modal Code Examples](modal.md#modal-code-examples).
9
+
10
+ ## Why `LightningModal`?
11
+
12
+ `LightningModal` provides a full-featured, modern, accessible modal solution intended for on and off the Salesforce platform (see [intended timeline](#intended-timeline-for-modal-solutions)) _that will **replace all** previous Lightning modal solutions_. Whether you are starting a completely new modal implementation, or have an existing modal implementation using a prior Aura or LWC modal solution, `LightningModal` is your Salesforce modal migration path *forward*.
13
+
14
+ **Why migrate to `LightningModal`?** The `LightningModal` component has fewer limitations, is actively supported for use both on the Salesforce platform (starting in 236) and off Salesforce platform (likely, starting in 238), has SLDS blueprints and accessibility best practices built in, is performant, provides a scroll bar when your modal content is taller than the screen height, and is well-tested. Using `LightningModal` gives your team more time to implement your app's unique features instead of recreating modal functionality.
15
+
16
+ ### Intended Timeline for Modal Solutions:
17
+ 1. `LightningModal`:
18
+ * Availability:
19
+ * for new Salesforce internal projects in release 236 via `lwc-components-lightning` package
20
+ * for new Salesforce internal _and_ planned for external projects in release 238 via `lightning-base-components` (npmjs.com) package
21
+ * Ongoing Support:
22
+ * starting in release 236 for Salesforce internal teams
23
+ 1. `lightning-dialog`:
24
+ * Availability:
25
+ * from 230, for all new modal projects, _within documented limited use cases_ (**not recommended in one.app**)
26
+ * **recommend** transitioning new Salesforce internal modal work to `LightningModal` starting in release 236
27
+ * Ongoing Support:
28
+ * for LWC modal projects, through end of 236, _within documented limited use cases_
29
+ * planned review for deprecation starting in 238
30
+ 1. `ui:createPanel`:
31
+ * Availability:
32
+ * for Aura modal projects through end of 236
33
+ * **recommend** transitioning new Salesforce internal modal work to `LightningModal` starting in release 236
34
+ * Ongoing Support:
35
+ * through the end of release 236
36
+ * planned review for deprecation starting in 238
37
+
38
+ ## Migrating Existing Modal Implementations
39
+
40
+ In this section, we’ll discuss migrating your existing modal implementation to `LightningModal` by showing the implementation differences in markup and APIs.
41
+
42
+ * **Migrating from custom modal implementations** using [SLDS modal blueprints](https://www.lightningdesignsystem.com/components/modals/)
43
+ * **Migrating from Aura** **`ui:createPanel`**
44
+ * **Migrating from** [**`lightning-dialog`**](https://git.soma.salesforce.com/aura/lightning-global/tree/master/ui-lightning-components/src/main/modules/lightning/dialog) (Salesforce internal only)
45
+
46
+ ## Key Points For Modal Code Migration
47
+
48
+ * **There isn't a `<lightning-modal>` tag!** Instead, you extend `LightningModal`, and call `.open()` and `.close()` on your modal implementation. You'll never use the `<lightning-modal>` tag within your code.
49
+ * **In most implementations, you’ll have, at minimum, two components**:
50
+ 1. your `CustomModal` modal component which defines behavior and is wrapped in the modal window
51
+ 1. your application component that imports your `CustomModal` component and calls `.open({})` to open your modal
52
+ * **You don’t need to set the base SLDS modal CSS classes, or manage the accessibility of the modal itself.** Each of the modal helper components have the SLDS styling classes and accessibility built in. However, you're responsible for making sure your modal’s content has accessibility covered!
53
+ * **Currently, auto-focus on the first interactive element is performed automatically** once at the beginning of modal creation.
54
+ * **You only work directly with helper components named `lightning-modal-*`**. `LightningModal` is actually a collection of supporting components that create the underlying LWC-based modal features and functionality. When you extend `LightningModal`, you can use the modal content helper components like `lightning-modal-header` (optional), `lightning-modal-body`, and `lightning-modal-footer` (optional) to set up the content of the modal, and call `.open()` in the `onclick` event handler of your app page's button or link.
55
+ * **We’ve provided a few `LightningModal` code examples for use in our LWR-based `playground.html` file, or our deprecated `demo/app` code playground to get you started.** Each of these examples is based on an SLDS blueprint pattern, and can be found in the '`modal/__examples__`' folder. Review the [Modal Code Examples](modal.md#modal-code-examples) section.
56
+
57
+ ## Migrating From a Custom Built Modal
58
+
59
+ If you have an existing LWC custom modal that implements the HTML and CSS from the [SLDS modal blueprint](https://www.lightningdesignsystem.com/components/modals/) and custom JavaScript behavior, you likely have your own custom api attributes and methods. We recommend the following:
60
+
61
+ * Start by looking at our [Modal Code Examples](modal.md#modal-code-examples) for comparison to your own implementation
62
+ * Each of these code examples can be viewed within the `modal/__examples__` folder
63
+ * Each can be previewed within our repo by editing the `playground.html` file (by running `yarn start`) or the deprecated `demo/app` and (running `yarn app:start`) utilizing the corresponding tag:
64
+ * `<modal-all>`
65
+ * `<modal-headless>`
66
+ * `<modal-footless>`
67
+ * Wrap the desired example tag within a `<template></template>` tag
68
+ * For modal blueprints and variants, review the [Modal and supported variants](modal.md#modal-and-supported-variants) section.
69
+ * `LightningModal` provides three helper components for header, body content, and footer sections. The `lightning-modal-body` is the only required component.
70
+ * You don’t need to worry about setting any of the base SLDS modal CSS classes. These are set for you. If you’d like to further style your modal, review the modal [Style Hooks](modal.md#style-hooks) section
71
+ * Review our `LightningModal` documentation:
72
+ * [Creating a Modal Component](modal.md#creating-a-modal-component)
73
+ * [Opening a Modal Instance](modal.md#opening-a-modal-instance)
74
+ * [About Modal Instances](modal.md#about-modal-instances)
75
+ * [Using the open() method](modal.md#using-the-open-method)
76
+ * [Using the close() method](modal.md#using-the-close-method)
77
+ * [Modal Code Examples](modal.md#modal-code-examples)
78
+
79
+ ## Migrating From Aura Modals
80
+
81
+ If you are ready to move an existing modal implementation from Aura-based `ui:createPanel`, `ui:createModal`, or `ui:modal`, here are some key differences:
82
+
83
+ ### Implementation differences
84
+
85
+ This section covers implementation differences between Aura modal solutions and `LightningModal`.
86
+
87
+ * When setting up the config before opening the modal, either pass your content via custom written `@api` (see [Using the open() method](modal.md#using-the-open-method)), or set it statically within your template (see the [Base Modal](modal.md#base-modal) HTML template example)
88
+ * If you don't want a header and title section, simply remove `lightning-modal-header`. You must then pass the required `label` value (for the accessible modal title) when opening the modal, for example `Modal.open({label: ‘Descriptive Modal Header’})`. See our [Headless Variant](modal.md#headless-variant) documentation, and [Modal Code Examples](modal.md#modal-code-examples). Same goes for the footer section, if you don’t want a footer, don't use `lightning-modal-footer`. Only `lightning-modal-body` is required.
89
+ * **For specific events and event listeners availability** within `createPanel` or `createModal`, for example, `onBeforeShow`, `onAfterShow`, `onCreate` or `onDestroy`, see our section on [About Modal Events](modal.md#about-modal-events).
90
+ * **Recommend:** create these as [custom events](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/events_create_dispatch)
91
+ * **If you want to get element reference,** for example, `linkElement.querySelector(‘[data-my-link]’)` within the content you’ve set within your modal, utilize data attributes. For this example, `<a href=“#” data-my-link>`, rather than relying on ID references, since these dynamically change in LWC).
92
+ * **Recommend:** See the note within the [ARIA attributes](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.create_components_accessibility_attributes) section.
93
+ * If you need to style aspects of your modal, you can apply CSS styles directly to your markup within the helper components.
94
+ * **Recommend:** See the example under [Directional Variant](modal.md#directional-variant) section.
95
+ * If you need to support a modal with a [directional variant](https://www.lightningdesignsystem.com/components/modals/#Directional), please review our [Directional Variant](modal.md#directional-variant) documentation.
96
+
97
+ ### API differences
98
+
99
+ This section covers `@api` or attribute differences between Aura modal solutions and `LightningModal`.
100
+
101
+ #### Supported APIs
102
+ See [ui:modal](https://git.soma.salesforce.com/aura/aura/tree/master/aura-components/src/main/components/ui/modal)
103
+
104
+ * `title` attribute has been changed to the `label` attribute
105
+ * You set the `label` attribute on the `lightning-modal-header` helper component or in the case of a headless modal, when you open the modal, you would set the `label` attribute when opening the modal. For example: `Modal.open({ label: ‘Modal Descriptive Title’ })`
106
+ * `**LightningModal**` currently has only four official attributes A
107
+ * `size` - to set the width of the modal
108
+ * `label` - to set the modal heading
109
+ * `description` - to set the modal's `aria-description` or `aria-describedby` property
110
+ * `disableClose` - a boolean value to toggle usability of the Close button
111
+ * **Modal enables you to pass in your own `@api`** to interact and wire-up your own desired functionality within the modal (interactive elements like buttons, inputs, etc) by setting key value pairs on `.open({ options: [], buttons: [] })`, for example
112
+ * **Modal enables setting event listeners** that may be listened to by the base LWC component (that opens the modal) by passing custom events into your LightningModal implementation by setting keys startin with `on` `.open({ onselect: () => { /* do stuff */ } })`, setting the corresponding listener on the outer templates markup, and firing the custom event `select` from within the modal. See [modal.md](modal.md#about-modal-events) for examples
113
+
114
+ #### Unsupported API
115
+ See [ui:modal](https://git.soma.salesforce.com/aura/aura/tree/master/aura-components/src/main/components/ui/modal)
116
+
117
+ * **Animation related:** `animation`, `closeAnimation`, `useTransition`
118
+ * **recommend:** remove for now, future support may be available
119
+ * **Close button related:** `closeAction`**,** `showCloseButton`, `closeButton`, `closeDialogLabel`
120
+ * **notes:** no recommendations, these properties cannot be altered currently
121
+ * **Setting CSS Classes related:** `class,` `modalClass`, `headerClass`, `bodyClass`, `footerClass`
122
+ * **recommend:** apply your required styles within the modal component. See the [Directional Variant](modal.md#directional-variant) section for an example.
123
+ * **Accessibility related:** trapFocus, ariaLabelleBy, ariaDescribedBy
124
+ * **notes:** the first two properties are managed for you, ariaDescribedBy feature will be added later
125
+ * **autoFocus** - **note:** this is currently happens automatically at open time
126
+ * **icon** - **note:** no current ability set an icon
127
+ * **titleDisplay** - note: not supported
128
+ * **Recommend:** If you don’t want a header section or title in the modal, set a descriptive label attribute value for accessibility, and don’t add the `lightning-modal-header` component.
129
+
130
+ ## Migrating From `lightning-dialog`
131
+
132
+ If you need to move an existing `lightning-dialog` implementation, you’ll need to consider these changes:
133
+
134
+ ### Implementation Differences
135
+
136
+ This section covers implementation differences between `lightning-dialog` and `LightningModal`.
137
+
138
+ * `lightning-dialog` and `LightningModal` are fairly similar in terms of their template code implementation, with the exception that the different sections within the `LightningModal` have separate helper components.
139
+ * `lightning-dialog` is inline with your application limiting the z-index to the context where it is placed. `LightningModal` is created outside and above all elements with a managed z-index to not conflict with other overlays.
140
+ * You implement `lightning-dialog` via its tag in your markup. There is no equivalent `lightning-modal`, instead you extend `LightningModal`. For example:
141
+ * import **LightningModal** from 'lightning/modal';
142
+ * export default class **MyModal _extends_ LightningModal** { /* your code */ }
143
+ * `LightningModal` makes use of extending `LightningOverlay` which provides `.open()` and `.close()` methods, whereas `lightning-dialog` worked from LWC declarative implementation without extends. See our sample [Modal Code Examples](modal.md#modal-code-examples) documentation.
144
+ * Custom events - `LightningModal` only provides a `privateclose` event. `<lightning-dialog>` provided events `cancel` or `close` events.
145
+
146
+ ### API and Method Differences
147
+
148
+ This section covers api or attribute and method differences between `lightning-dialog` and `LightningModal`.
149
+
150
+ * The API to indicate the modal's title or heading is renamed from `header` to `label`
151
+ * From: `<lightning-dialog header=“Descriptive Modal Heading”>`
152
+ * To:
153
+ 1. `<lightning-modal-header label=“Descriptive Modal Heading”>` for modal with header section
154
+ 1. Or, `MyModal.open({ label: ‘Descriptive Modal Heading’ })` for headless modal
155
+ * The method to show the modal is renamed
156
+ * From: `.showModal()`
157
+ * To: `.open()`
158
+ * `.open()` is inherited when you extend LightningModal.
@@ -0,0 +1,414 @@
1
+ A `lightningModal` component overlays a message modal on top of the current app window. A modal interrupts a user’s workflow and draws attention to the message.
2
+
3
+ `LightningModal` implements the SLDS [modals](https://www.lightningdesignsystem.com/components/modals/) blueprint.
4
+
5
+ Create a modal component in response to a user action, such as clicking a button or link. The modal blocks interaction with everything else on the page until the user acts upon or dismisses the modal.
6
+
7
+ Unlike other components, this component doesn't use a `lightning-modal` tag or extend `LightningElement`. There is no `lightning-modal` component. Instead, you create a modal by extending `LightningModal` and using these helper `lightning-modal-*` components to provide a header, footer and the body of the modal.
8
+ - `lightning-modal-body`
9
+ - `lightning-modal-header`
10
+ - `lightning-modal-footer`
11
+
12
+ To create a modal component, import `LightningModal` from `lightning/modal`. The component has access to the normal LWC resources as well as the special container, helper components, methods, and events of the `lightning/modal` module.
13
+
14
+ In this example, the `content` property passes data to the modal from the component that invokes it.
15
+
16
+ ```js
17
+ /* c/myModal.js */
18
+
19
+ import { api } from 'lwc';
20
+ import LightningModal from 'lightning/modal';
21
+
22
+ export default class MyModal extends LightningModal {
23
+ @api content;
24
+
25
+ handleOkay() {
26
+ this.close('okay');
27
+ }
28
+ }
29
+ ```
30
+
31
+ The modal’s HTML template uses helper `lightning-modal-*` components to provide a header, footer, and the body of the modal. In this example, the content for the modal body comes from the `content` property we defined in the modal's JavaScript file.
32
+
33
+ ```html
34
+ <!-- c/myModal.html -->
35
+
36
+ <template>
37
+ <lightning-modal-header label="My Modal Heading"></lightning-modal-header>
38
+ <lightning-modal-body> Content: {content} </lightning-modal-body>
39
+ <lightning-modal-footer>
40
+ <lightning-button label="OK" onclick={handleOkay}></lightning-button>
41
+ </lightning-modal-footer>
42
+ </template>
43
+ ```
44
+
45
+ The `lightning-modal-body` component is required for the modal template.
46
+
47
+ The `lightning-modal-header` and `lightning-modal-footer` components are optional, but recommended. The `lightning-modal-*` components render in the order they appear in the template. Place the `lightning-modal-body` component after `lightning-modal-header` and before the `lightning-modal-footer` component.
48
+
49
+ #### Open a Modal Instance
50
+
51
+ `LightningModal` provides an `.open()` method which opens a modal and returns a promise that asynchronously resolves with the result of the user’s interaction with the modal.
52
+
53
+ Each invocation of a modal component’s `.open()` method creates a unique instance of the modal. You can think of a modal as a self-contained application that starts from scratch when it opens. It displays the content you pass in through the `.open()` method or that you set within the modal's HTML template.
54
+
55
+ When you close a modal, the modal instance is destroyed, not hidden. On close, the modal must save the user’s input data or pass it to the invoking component as the promise result. Otherwise, the data is lost when the modal instance is closed.
56
+
57
+ The `.open()` method lets you assign values to the modal's properties. `LightningModal` provides these properties.
58
+
59
+ * `label` - Required. Sets the modal's title and assistive device label. If the modal has a header, set `label` in the `lightning-modal-header` component. If the modal doesn't have a header, set the `label` property when opening the modal.
60
+
61
+ * `size` - Determines how much of the viewport width the modal uses. Supported values are `small`, `medium`, and `large`, which you can set when you open the modal. Default value is `medium`. The length of the modal is determined by the amount of content.
62
+
63
+ * `description` - Sets the modal's accessible description. It uses the `aria-description` attribute where supported, or falls back to `aria-describedby`. If you set a custom description value, include the label name at the beginning of your description, because some screen readers only read the description, and not the label.
64
+
65
+ * `disableClose` - Prevents closing the modal by normal means like the ESC key, the close button, or `.close()`. For example, you could briefly set `disableClose` to true while a completed form is saving, so the user doesn't dismiss the modal early. See [**Use the `disableClose` Attribute**](#use-the-disableclose-attribute).
66
+
67
+ In this example, the app opens the `myModal` component. It invokes the `.open()` method in a `handleClick()` function bound to the app button’s `onclick` attribute, and uses `async` and `await` keywords to handle the promise returned by `.open()`. This example overrides the `size` value by setting it to `large` and sets the modal’s user-defined property `content`.
68
+
69
+ ```js
70
+ /* c/myApp.js */
71
+
72
+ import { LightningElement } from 'lwc';
73
+ import MyModal from 'c/myModal';
74
+
75
+ export default class MyApp extends LightningElement {
76
+ async handleClick() {
77
+ const result = await MyModal.open({
78
+ // `label` is not included here in this example.
79
+ // it is set on lightning-modal-header instead
80
+ size: 'large',
81
+ description: 'Accessible description of modal\'s purpose',
82
+ content: 'Passed into content api',
83
+ });
84
+ // if modal closed with X button, promise returns result = 'undefined'
85
+ // if modal closed with OK button, promise returns result = 'okay'
86
+ console.log(result);
87
+ }
88
+ }
89
+ ```
90
+ The HTML template for this app contains a button that opens the modal and displays the result returned when the modal closes.
91
+
92
+ ```html
93
+ <!-- c/myApp.html -->
94
+
95
+ <template>
96
+ <lightning-button
97
+ onclick={handleClick}
98
+ aria-haspopup="modal"
99
+ label="Open My Modal">
100
+ </lightning-button>
101
+ <p>Result: {result}</p>
102
+ </template>
103
+ ```
104
+
105
+ You can also use `.open()` to pass data from your invoking component into the modal with custom properties decorated with `@api`. These properties can be any type, such as a string or an object that’s an array of key/value pairs to be assigned to the new modal instance.
106
+
107
+ For example, this app component sets an `options` property to a set of key/value pairs in `MyModal.open()`. The promise is handled using an arrow function that logs the result to the console.
108
+
109
+ ```js
110
+ /* c/myApp.js */
111
+
112
+ import { LightningElement } from "lwc";
113
+ import MyModal from "c/myModal";
114
+
115
+ export default class MyPage extends LightningElement {
116
+ handleOpenClick() {
117
+ MyModal.open({
118
+ // maps to developer-created `@api options`
119
+ options: [
120
+ { id: 1, label: 'Option 1' },
121
+ { id: 2, label: 'Option 2' },
122
+ ]
123
+ }).then((result) => {
124
+ console.log(result);
125
+ });
126
+ }
127
+ }
128
+ ```
129
+ The modal dialog can then use this property. In this case, the modal creates buttons whose labels are provided in the `options` array.
130
+
131
+ ```js
132
+ /* c/myModal.js */
133
+
134
+ import { api } from 'lwc';
135
+ import LightningModal from 'lightning/modal';
136
+
137
+ export default class MyModal extends LightningModal {
138
+ // Data is passed to api properties via .open({ options: [] })
139
+ @api options = [];
140
+ }
141
+ ```
142
+
143
+ ```html
144
+ <!-- c/myModal.html -->
145
+
146
+ <template>
147
+ <lightning-modal-header label="My Modal Heading"></lightning-modal-header>
148
+ <lightning-modal-body>
149
+ Let's make some buttons!
150
+ <template for:each={options} for:item="option">
151
+ <lightning-button
152
+ onclick={handleOptionClick}
153
+ data-id={option.id}
154
+ key={option.id}
155
+ >
156
+ {option.label}
157
+ </lightning-button>
158
+ </template>
159
+ </lightning-modal-body>
160
+ </template>
161
+ ```
162
+
163
+ #### Close a Modal Instance
164
+
165
+ Use `this.close(result)` to close the modal, where `result` is anything you want to return from the modal. The `.close()` operation is asynchronous to display a brief fade out animation before the modal is destroyed. The `result` data can’t be modified after the close operation begins.
166
+
167
+ You can also close the modal with the default close button, the X at the top right corner. Closing a modal like this is the same as calling `this.close()` with an `undefined` result, so any data input is lost.
168
+
169
+ This example shows the handler for some buttons inside a modal. When the user clicks the button, `this.close(id)` returns the option that they chose and the modal closes.
170
+
171
+ ```js
172
+ /* c/myModal.js */
173
+
174
+ import { api } from 'lwc';
175
+ import LightningModal from 'lightning/modal';
176
+
177
+ export default class MyModal extends LightningModal {
178
+ // Data is passed to apis via .open({ options: [] })
179
+ @api options = [];
180
+
181
+ handleOptionClick(e) {
182
+ const { target } = e;
183
+ const { id } = target.dataset;
184
+ // this.close() triggers closing the modal
185
+ // the value of `id` is passed as the result
186
+ this.close(id);
187
+ }
188
+ }
189
+ ```
190
+
191
+ ```html
192
+ <!-- c/myModal.html -->
193
+
194
+ <template>
195
+ <template for:each={options} for:item="option">
196
+ <lightning-button
197
+ onclick={handleOptionClick}
198
+ data-id={option.id}
199
+ key={option.id}
200
+ >
201
+ {option.label}
202
+ </lightning-button>
203
+ </template>
204
+ </template>
205
+ ```
206
+
207
+ #### Use the `disableClose` Attribute
208
+
209
+ `disableClose` temporarily turns off the ability to dismiss the modal by normal means like the ESC key, the close button, or `this.close()`. For example, you could briefly set `disableClose` to `true` while a completed form is saving, so the user doesn't dismiss the modal early.
210
+
211
+ Preventing a modal's close should be a temporary state. Use `disableClose` for less than 5 seconds. Accessibility is affected if you trap keyboard focus inappropriately. See [No Keyboard Trap](https://www.w3.org/TR/UNDERSTANDING-WCAG20/keyboard-operation-trapping.html) for more information.
212
+
213
+ When the process using `disableClose` finishes successfully, dismiss the modal. If the process using `disableClose` fails, re-enable the ability to dismiss the modal with `disableClose = false`, or give feedback to help the user resolve the issue.
214
+
215
+ While `disableClose` is `true`, disable any processes or UI buttons that might call `Modal.close()`.
216
+
217
+ This example shows how to use `disableClose`. It's not a fully functional example, but could be used in a complex modal component.
218
+
219
+ ```js
220
+ /* c/myModalForm.js */
221
+ /* This is intended as a mock example, not as fully functional code */
222
+ /* NOTE: observe values set:
223
+ this.disableClose (in JS),
224
+ and this.saveInProcess (in JS and HTML)
225
+ */
226
+ import { api } from 'lwc';
227
+ import LightningModal from 'lightning/modal';
228
+
229
+ export default class MyModalForm extends LightningModal {
230
+ // formData is utilized for saving current form values
231
+ formData = {};
232
+ failureType = null;
233
+ saveStatus = {};
234
+ saveInProcess = false;
235
+
236
+ handleCloseClick() {
237
+ this.close('canceled');
238
+ }
239
+
240
+ closeModal() {
241
+ // immediately exits, so no need to trigger
242
+ // this.disableClose = false OR
243
+ // this.saveInProcess = false;
244
+ // modal is destroyed, and focus moves
245
+ // back to originally clicked item that
246
+ // generated the modal
247
+ this.close('success');
248
+ }
249
+
250
+ mitigateSaveFailure() {
251
+ // depending on how easily the failure can be resolved
252
+ // you may need to immediately set disableClose = false
253
+ if (this.failureType === 'recoverable') {
254
+ // no need to call this.disableClose = false
255
+ // or this.saveInProgress = false yet
256
+ tryToFixFailure();
257
+ } else {
258
+ // can't resolve the error
259
+ // need to allow users to exit modal
260
+ this.disableClose = false;
261
+ this.saveInProcess = false;
262
+ // mock function to indicate modal state
263
+ // while still allowing user to exit
264
+ // preventing keyboard trap
265
+ reportUnresolvableError();
266
+ }
267
+ }
268
+
269
+ async saveData() {
270
+ // switches disabled state on buttons
271
+ this.saveInProcess = true;
272
+ const saveStatus = await sendData(this.formData);
273
+ return (saveStatus && saveStatus.success)
274
+ ? closeModal()
275
+ : mitigateSaveFailure();
276
+ }
277
+
278
+ async handleSaveClick() {
279
+ if (isValid(this.formData)) {
280
+ // begin saving data, temporarily disable
281
+ // LightningModal's close button
282
+ // Be sure to reenable the close button, by setting
283
+ // this.disableClose = false, IF further interaction
284
+ // is desired before the modal closes
285
+ this.disableClose = true;
286
+ await saveData();
287
+ } else {
288
+ // function that display form errors based on data
289
+ showFormErrors(this.formData);
290
+ }
291
+ }
292
+ }
293
+ ```
294
+
295
+ ```html
296
+ <!-- c/myModalForm.html -->
297
+
298
+ <template>
299
+ <lightning-modal-header
300
+ label="My Modal Heading"
301
+ ></lightning-modal-header>
302
+ <lightning-modal-body>
303
+ <!-- form here -->
304
+ </lightning-modal-body>
305
+ <lightning-modal-footer>
306
+ <button
307
+ disabled={saveInProcess}
308
+ onclick={handleCloseClick}
309
+ aria-label="Cancel and close"
310
+ >Cancel</button>
311
+ <button
312
+ disabled={saveInProcess}
313
+ onclick={handleSaveClick}
314
+ >Save</button>
315
+ </lightning-modal-footer>
316
+ </template>
317
+ ```
318
+
319
+ #### Modal Events
320
+
321
+ A modal can only fire events captured by the component that opened it, not the modal itself. Normal techniques can't catch events that fire from the modal, because the events bubble up to a top root element outside of the component that opened the modal.
322
+
323
+ To capture modal events, attach them in the `.open()` method invoked by the component that opens the modal.
324
+
325
+ For example, here's a custom `select` event dispatched from `MyModal`.
326
+
327
+ ```js
328
+ /* c/myModal.js */
329
+ dispatchSelectEvent(e) {
330
+ // e.target might represent an input with an id and value
331
+ const { id, value } = e.target;
332
+ const selectEvent = new CustomEvent('select', {
333
+ detail: { id, value }
334
+ });
335
+ this.dispatchEvent(selectEvent);
336
+ }
337
+ ```
338
+
339
+ The `open()` method in `myApp` defines the `onselect` event handler. This example uses `onselect` to proxy events that we want to pass through.
340
+
341
+ ```js
342
+ /* c/myApp.js */
343
+
344
+ // ...
345
+ // Process the select event from within the modal
346
+ handleSelectEvent(detail) {
347
+ const { id, value } = detail;
348
+ console.log(`select event fired elem with id ${id} and value: ${value}`);
349
+ }
350
+
351
+ // ...
352
+ // Trigger visibility of the modal
353
+ handleOpenModal() {
354
+ MyModal.open({
355
+ label: 'Modal Title',
356
+ size: 'large',
357
+ description: 'Modal Title with brief description',
358
+ // event triggered when new CustomEvent('select', {detail: {}});
359
+ // occurs *from within* LightningModal.
360
+ // see dispatchSelectEvent() in c/myModal.js above
361
+ onselect: (e) => {
362
+ // stop further propagation of the event
363
+ e.stopPropagation();
364
+ // hand off to separate function to process
365
+ // result of the event (see above in this example)
366
+ this.handleSelectEvent(e.detail);
367
+ // or proxy to be handled above by dispatching
368
+ // another custom event to pass on the event
369
+ // this.dispatchEvent(e);
370
+ }
371
+ });
372
+ }
373
+ ```
374
+
375
+ See [Create and Dispatch Events](https://developer.salesforce.com/docs/component-library/documentation/en/lwc/events_create_dispatch) in the LWC Dev Guide for more information about events.
376
+
377
+ #### Styling Variants
378
+
379
+ The `lightning-modal-header` and `lightning-modal-footer` child components are optional, and you can choose to not include one or the other in your modal.
380
+
381
+ The headerless variant of `LightningModal` has these additional requirements.
382
+ - Must set a descriptive modal title with the `label` property using `Modal.open({ label })` or you’ll get a console error.
383
+ - The `label` property is required for all variants of `LightningModal`. Assistive devices read the `label` value, even though the headerless modal variant doesn't display the label.
384
+ - Because this variant doesn't use `lightning-modal-header`, you have to manually create an `<h1>` heading in `lightning-modal-body`. Provide accessible structure by starting with heading level `<h1>` and using levels up to `<h6>` appropriately. For more information, see [Semantic Structure, Headings on WebAim.org](https://webaim.org/techniques/semanticstructure/#headings).
385
+
386
+ The `LightningModal` component also supports the SLDS [Directional variant](https://www.lightningdesignsystem.com/components/modals/#Directional) modal blueprint pattern.
387
+
388
+ To achieve the directional button layout, place the buttons in a `div` with the `slds-modal__footer_directional` class.
389
+
390
+ ```html
391
+ <!-- c/modalDirectional.html -->
392
+
393
+ <template>
394
+ <lightning-modal-body> Content: {content} </lightning-modal-body>
395
+ <lightning-modal-footer>
396
+ <div class=“slds-modal__footer_directional”>
397
+ <lightning-button label="NO" onclick={handleNo}></lightning-button>
398
+ <lightning-button label="OK" onclick={handleOkay}></lightning-button>
399
+ </div>
400
+ </lightning-modal-footer>
401
+ </template>
402
+ ```
403
+
404
+ #### Styling Hooks
405
+
406
+ The `lightning-modal-*` helper components support [style hooks](https://www.lightningdesignsystem.com/components/modals/#Styling-Hooks-Overview). The styling hooks for the template that invokes the helper components doesn't carry over to them, so you must style each helper component individually.
407
+
408
+ Customizing the styling on the white modal frame and background, close button, or gray backdrop isn't supported.
409
+
410
+ #### Accessibility
411
+
412
+ The `lightning-modal-header` component renders the `label` value in an `<h1>` element. If your modal uses the header, begin any additional heading levels in the modal with `<h2>` for accessibility. Provide accessible structure by using heading levels up to `<h6>` appropriately. For more information, see [Semantic Structure, Headings on WebAim.org](https://webaim.org/techniques/semanticstructure/#headings).
413
+
414
+ To include tagline text or link content for the header section, add it between the `<lightning-modal-header>` tags.
@@ -0,0 +1,7 @@
1
+ .example {
2
+ margin: 0.5rem;
3
+ border-radius: 0.5rem;
4
+ background: #FFF;
5
+ box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.2);
6
+ padding: 1rem;
7
+ }
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <div class="example">
3
+ <button
4
+ onclick={handleDemoModal}
5
+ aria-haspopup="modal"
6
+ >Open the Modal</button>
7
+ <p>Result: <code>{demoResult}</code></p>
8
+ </div>
9
+ </template>
@@ -0,0 +1,25 @@
1
+ import { LightningElement } from 'lwc';
2
+ import ModalDemoAll from 'modal/demoall';
3
+
4
+ export default class ModalAll extends LightningElement {
5
+ demoResult = 'unset';
6
+
7
+ handleDemoModal() {
8
+ ModalDemoAll.open({
9
+ // LightningModal
10
+ size: 'small',
11
+ // ModalDemo
12
+ options: [
13
+ { id: 1, variant: 'neutral', label: 'Option 1' },
14
+ { id: 2, variant: 'neutral', label: 'Option 2' },
15
+ { id: 3, variant: 'brand', label: 'Main Option' },
16
+ ],
17
+ }).then((result) => {
18
+ if (result === null) {
19
+ this.demoResult = 'dismiss';
20
+ } else {
21
+ this.demoResult = result;
22
+ }
23
+ });
24
+ }
25
+ }
@@ -0,0 +1,7 @@
1
+ .example {
2
+ margin: 0.5rem;
3
+ border-radius: 0.5rem;
4
+ background: #FFF;
5
+ box-shadow: 0 1px 0.25rem rgba(0, 0, 0, 0.2);
6
+ padding: 1rem;
7
+ }
@@ -0,0 +1,9 @@
1
+ <template>
2
+ <div class="example">
3
+ <button
4
+ onclick={handleDemoModal}
5
+ aria-haspopup="modal"
6
+ >Open the Modal</button>
7
+ <p>Result: <code>{demoResult}</code></p>
8
+ </div>
9
+ </template>