@momentum-design/components 0.83.3 → 0.83.5

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.
@@ -12,6 +12,11 @@ declare const Dialog_base: import("../../utils/mixins/index.types").Constructor<
12
12
  * If a `triggerId` is provided, the dialog will manage focus with that element, otherwise it will
13
13
  * remember the previously focused element before the dialog was opened.
14
14
  *
15
+ * The dialog is a controlled component, meaning it does not have its own state management for visibility.
16
+ * Use the `visible` property to control the visibility of the dialog.
17
+ * Use the `onClose` event to handle the close action of the dialog (fired when Close button is clicked
18
+ * or Escape is pressed).
19
+ *
15
20
  * Dialog component have 2 variants: default and promotional.
16
21
  *
17
22
  * **Accessibility notes for consuming (have to be explicitly set when you consume the component)**
@@ -32,6 +37,8 @@ declare const Dialog_base: import("../../utils/mixins/index.types").Constructor<
32
37
  * @event hidden - (React: onHidden) Dispatched when the dialog is hidden
33
38
  * @event created - (React: onCreated) Dispatched when the dialog is created (added to the DOM)
34
39
  * @event destroyed - (React: onDestroyed) Dispatched when the dialog is destroyed (removed from the DOM)
40
+ * @event close - (React: onClose) Dispatched when the Close Button is clicked or Escape key is pressed
41
+ * (this does not hide the dialog)
35
42
  *
36
43
  * @cssproperty --mdc-dialog-primary-background-color - primary background color of the dialog
37
44
  * @cssproperty --mdc-dialog-border-color - border color of the dialog
@@ -63,6 +70,8 @@ declare class Dialog extends Dialog_base {
63
70
  triggerId?: string;
64
71
  /**
65
72
  * The visibility of the dialog
73
+ *
74
+ * Dialog is a controlled component, visible is the only property that controls the visibility of the dialog.
66
75
  * @default false
67
76
  */
68
77
  visible: boolean;
@@ -176,6 +185,12 @@ declare class Dialog extends Dialog_base {
176
185
  * @internal
177
186
  */
178
187
  private createBackdrop;
188
+ /**
189
+ * Fired when Close Button is clicked or Escape key is pressed.
190
+ * This method dispatches the close event. Setting visible to false
191
+ * has to be done by the consumer of the component.
192
+ */
193
+ private closeDialog;
179
194
  /**
180
195
  * Handles the escape keydown event to close the dialog.
181
196
  * @internal
@@ -197,16 +212,6 @@ declare class Dialog extends Dialog_base {
197
212
  * @internal
198
213
  */
199
214
  private focusBackToTrigger;
200
- /**
201
- * Hides the dialog.
202
- * @internal
203
- */
204
- hideDialog: () => void;
205
- /**
206
- * Shows the dialog.
207
- * @internal
208
- */
209
- showDialog: () => void;
210
215
  render(): import("lit-html").TemplateResult<1>;
211
216
  static styles: Array<CSSResult>;
212
217
  }
@@ -29,6 +29,11 @@ import { CardAndDialogFooterMixin } from '../../utils/mixins/CardAndDialogFooter
29
29
  * If a `triggerId` is provided, the dialog will manage focus with that element, otherwise it will
30
30
  * remember the previously focused element before the dialog was opened.
31
31
  *
32
+ * The dialog is a controlled component, meaning it does not have its own state management for visibility.
33
+ * Use the `visible` property to control the visibility of the dialog.
34
+ * Use the `onClose` event to handle the close action of the dialog (fired when Close button is clicked
35
+ * or Escape is pressed).
36
+ *
32
37
  * Dialog component have 2 variants: default and promotional.
33
38
  *
34
39
  * **Accessibility notes for consuming (have to be explicitly set when you consume the component)**
@@ -49,6 +54,8 @@ import { CardAndDialogFooterMixin } from '../../utils/mixins/CardAndDialogFooter
49
54
  * @event hidden - (React: onHidden) Dispatched when the dialog is hidden
50
55
  * @event created - (React: onCreated) Dispatched when the dialog is created (added to the DOM)
51
56
  * @event destroyed - (React: onDestroyed) Dispatched when the dialog is destroyed (removed from the DOM)
57
+ * @event close - (React: onClose) Dispatched when the Close Button is clicked or Escape key is pressed
58
+ * (this does not hide the dialog)
52
59
  *
53
60
  * @cssproperty --mdc-dialog-primary-background-color - primary background color of the dialog
54
61
  * @cssproperty --mdc-dialog-border-color - border color of the dialog
@@ -76,6 +83,8 @@ class Dialog extends PreventScrollMixin(FocusTrapMixin(CardAndDialogFooterMixin(
76
83
  this.id = '';
77
84
  /**
78
85
  * The visibility of the dialog
86
+ *
87
+ * Dialog is a controlled component, visible is the only property that controls the visibility of the dialog.
79
88
  * @default false
80
89
  */
81
90
  this.visible = DEFAULTS.VISIBLE;
@@ -167,21 +176,7 @@ class Dialog extends PreventScrollMixin(FocusTrapMixin(CardAndDialogFooterMixin(
167
176
  // Prevent the event from propagating to the document level
168
177
  // pressing escape on a dialog should only close the dialog, nothing else
169
178
  event.stopPropagation();
170
- this.hideDialog();
171
- };
172
- /**
173
- * Hides the dialog.
174
- * @internal
175
- */
176
- this.hideDialog = () => {
177
- this.visible = false;
178
- };
179
- /**
180
- * Shows the dialog.
181
- * @internal
182
- */
183
- this.showDialog = () => {
184
- this.visible = true;
179
+ this.closeDialog();
185
180
  };
186
181
  }
187
182
  connectedCallback() {
@@ -307,6 +302,14 @@ class Dialog extends PreventScrollMixin(FocusTrapMixin(CardAndDialogFooterMixin(
307
302
  (_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.appendChild(backdrop);
308
303
  this.backdropElement = backdrop;
309
304
  }
305
+ /**
306
+ * Fired when Close Button is clicked or Escape key is pressed.
307
+ * This method dispatches the close event. Setting visible to false
308
+ * has to be done by the consumer of the component.
309
+ */
310
+ closeDialog() {
311
+ DialogEventManager.onCloseDialog(this, false);
312
+ }
310
313
  /**
311
314
  * Handles the dialog visibility change.
312
315
  * Handles the exit event to close the dialog.
@@ -390,7 +393,7 @@ class Dialog extends PreventScrollMixin(FocusTrapMixin(CardAndDialogFooterMixin(
390
393
  variant="${BUTTON_VARIANTS.TERTIARY}"
391
394
  size="${ICON_BUTTON_SIZES[20]}"
392
395
  aria-label="${ifDefined(this.closeButtonAriaLabel) || ''}"
393
- @click="${this.hideDialog}"
396
+ @click="${this.closeDialog}"
394
397
  ></mdc-button>
395
398
  <div part="body">
396
399
  <slot name="dialog-body"></slot>
@@ -6,7 +6,7 @@ export declare class DialogEventManager {
6
6
  * @param eventName - The name of the event.
7
7
  * @param instance - The dialog instance.
8
8
  */
9
- static dispatchDialogEvent(eventName: string, instance: Dialog): void;
9
+ static dispatchDialogEvent(eventName: string, instance: Dialog, bubbles?: boolean): void;
10
10
  /**
11
11
  * Custom event that is fired when the dialog is shown.
12
12
  *
@@ -19,6 +19,14 @@ export declare class DialogEventManager {
19
19
  * @param instance - The dialog instance.
20
20
  */
21
21
  static onHideDialog(instance: Dialog): void;
22
+ /**
23
+ * Custom event that is fired when the dialog is closed.
24
+ * This gets fired when the Close Button is clicked or
25
+ * when Escape key is pressed.
26
+ *
27
+ * @param instance - The dialog instance.
28
+ */
29
+ static onCloseDialog(instance: Dialog, bubbles?: boolean): void;
22
30
  /**
23
31
  * Custom event that is fired when the dialog is created.
24
32
  *
@@ -5,11 +5,11 @@ export class DialogEventManager {
5
5
  * @param eventName - The name of the event.
6
6
  * @param instance - The dialog instance.
7
7
  */
8
- static dispatchDialogEvent(eventName, instance) {
8
+ static dispatchDialogEvent(eventName, instance, bubbles = true) {
9
9
  instance.dispatchEvent(new CustomEvent(eventName, {
10
10
  detail: { show: instance.visible },
11
11
  composed: true,
12
- bubbles: true,
12
+ bubbles,
13
13
  }));
14
14
  }
15
15
  /**
@@ -28,6 +28,16 @@ export class DialogEventManager {
28
28
  static onHideDialog(instance) {
29
29
  this.dispatchDialogEvent('hidden', instance);
30
30
  }
31
+ /**
32
+ * Custom event that is fired when the dialog is closed.
33
+ * This gets fired when the Close Button is clicked or
34
+ * when Escape key is pressed.
35
+ *
36
+ * @param instance - The dialog instance.
37
+ */
38
+ static onCloseDialog(instance, bubbles = true) {
39
+ this.dispatchDialogEvent('close', instance, bubbles);
40
+ }
31
41
  /**
32
42
  * Custom event that is fired when the dialog is created.
33
43
  *
@@ -8,5 +8,6 @@ interface Events {
8
8
  onHiddenEvent: Event;
9
9
  onCreatedEvent: Event;
10
10
  onDestroyedEvent: Event;
11
+ onCloseEvent: Event;
11
12
  }
12
13
  export type { DialogSize, DialogRole, DialogVariant, Events };