@api-client/ui 0.5.18 → 0.5.19

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.
@@ -15,6 +15,7 @@ export interface UiDialogClosingReason {
15
15
  value?: unknown;
16
16
  }
17
17
  interface DialogEventMap {
18
+ closing: CustomEvent<UiDialogClosingReason>;
18
19
  close: CustomEvent<UiDialogClosingReason>;
19
20
  }
20
21
  export type RenderFunction = () => TemplateResult;
@@ -64,6 +65,8 @@ export type RenderFunction = () => TemplateResult;
64
65
  * @slot title - The slot to place the dialog title. Do not put elements here, just the text.
65
66
  * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`
66
67
  * buttons to automatically close the dialog.
68
+ * @fires closing - A cancelable, non-bubbling event with the `UiDialogClosingReason` as the detail,
69
+ * dispatched before the dialog closes. If prevented, the dialog will not close.
67
70
  * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.
68
71
  */
69
72
  export default class UiDialog extends UiElement implements TypedEvents<DialogEventMap> {
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.d.ts","sourceRoot":"","sources":["../../../../../src/md/dialog/internals/Dialog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,KAAK,cAAc,EAAE,KAAK,cAAc,EAAe,MAAM,KAAK,CAAA;AAGlH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD,OAAO,2BAA2B,CAAA;AAGlC,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAA;IAClB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAED,UAAU,cAAc;IACtB,KAAK,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAA;CAC1C;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,cAAc,CAAA;AAE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UAAU,IAAI,cAAc;IAStC,SAAS,CAAC,aAAa,IAAI,cAAc;CAiD1C"}
@@ -403,13 +403,25 @@ let UiDialog = (() => {
403
403
  if (!['dismiss', 'confirm'].includes(value)) {
404
404
  return;
405
405
  }
406
- this.open = false;
407
406
  const detail = {
408
407
  cancelled: value === 'dismiss',
409
408
  };
410
409
  if (this.dialogValue !== undefined) {
411
410
  detail.value = this.dialogValue;
412
411
  }
412
+ // Dispatch cancelable closing event first
413
+ const closingEvent = new CustomEvent('closing', {
414
+ cancelable: true,
415
+ composed: false,
416
+ bubbles: false,
417
+ detail,
418
+ });
419
+ const canClose = this.dispatchEvent(closingEvent);
420
+ // Only proceed with closing if the event wasn't canceled
421
+ if (!canClose) {
422
+ return;
423
+ }
424
+ this.open = false;
413
425
  this.dispatchEvent(new CustomEvent('close', {
414
426
  composed: true,
415
427
  detail,
@@ -419,8 +431,31 @@ let UiDialog = (() => {
419
431
  if (!this.open) {
420
432
  return;
421
433
  }
434
+ const detail = {
435
+ cancelled: true,
436
+ };
437
+ if (this.dialogValue !== undefined) {
438
+ detail.value = this.dialogValue;
439
+ }
440
+ // Dispatch cancelable closing event first
441
+ const closingEvent = new CustomEvent('closing', {
442
+ cancelable: true,
443
+ composed: false,
444
+ bubbles: false,
445
+ detail,
446
+ });
447
+ const canClose = this.dispatchEvent(closingEvent);
448
+ // Only proceed with closing if the event wasn't canceled
449
+ if (!canClose) {
450
+ // If closing was prevented, reopen the dialog
451
+ this.dialog.showModal();
452
+ return;
453
+ }
422
454
  this.open = false;
423
- this.handleInteraction('dismiss');
455
+ this.dispatchEvent(new CustomEvent('close', {
456
+ composed: true,
457
+ detail,
458
+ }));
424
459
  }
425
460
  handleDismiss() {
426
461
  this.handleInteraction('dismiss');
@@ -591,6 +626,8 @@ let UiDialog = (() => {
591
626
  * @slot title - The slot to place the dialog title. Do not put elements here, just the text.
592
627
  * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`
593
628
  * buttons to automatically close the dialog.
629
+ * @fires closing - A cancelable, non-bubbling event with the `UiDialogClosingReason` as the detail,
630
+ * dispatched before the dialog closes. If prevented, the dialog will not close.
594
631
  * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.
595
632
  */
596
633
  export default UiDialog;
@@ -1 +1 @@
1
- {"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../../../src/md/dialog/internals/Dialog.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,IAAI,EAAE,OAAO,EAA4C,WAAW,EAAE,MAAM,KAAK,CAAA;AAClH,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACrG,OAAO,EAAkB,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAGlE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAC9E,OAAO,2BAA2B,CAAA;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;;sBAqEd,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAA1B,QAAS,SAAQ,WAAS;;;wCAS5C,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;iCAc1C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;gCAO3B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;wCAO3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wCAO1B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;uCAO1B,QAA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,QAAQ,CAAA;YAC1C,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,iBAAiB,CAAA;YACnF,OAAO,IAAI,CAAA;;;gBAGC,IAAI;iBACH,YAAY;iBACZ,WAAW;kBACV,IAAI,CAAC,aAAa;;WAEzB,YAAY;;KAElB,CAAA;QACH,CAAC;;;AAzdH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBA0aC","sourcesContent":["import { type CSSResultOrNative, html, nothing, type PropertyValues, type TemplateResult, adoptStyles } from 'lit'\nimport { property, query, queryAssignedElements, queryAssignedNodes, state } from 'lit/decorators.js'\nimport { type ClassInfo, classMap } from 'lit/directives/class-map.js'\nimport { UiElement } from '../../UiElement.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiButton from '../../button/internals/button.js'\nimport type { TypedEvents } from '../../../core/types.js'\nimport { ifDefined } from 'lit/directives/if-defined.js'\nimport { SyntheticSubmitEvent } from '../../../events/SyntheticSubmitEvent.js'\nimport '../../button/ui-button.js'\nimport { bound } from '../../../decorators/bound.js'\n\nexport interface UiDialogClosingReason {\n /**\n * Whether the dialog was cancelled by either activating the `dismiss` button\n * or by pressing escape.\n */\n cancelled: boolean\n /**\n * This is used in cases when the dialog has more complex purpose.\n * This is the value expected from the dialog.\n */\n value?: unknown\n}\n\ninterface DialogEventMap {\n close: CustomEvent<UiDialogClosingReason>\n}\n\nexport type RenderFunction = () => TemplateResult\n\n/**\n * Styled dialog using a native `<dialog>` element under the hood.\n * Note, since native dialog renders in the top layer it is not necessary\n * to place the dialog in the `<body>`.\n *\n * **Using Buttons**\n *\n * The dialog automatically recognizes buttons with values `confirm` and `dismiss`\n * to close the dialog and dispatch the `close` event. The event has additional\n * closing reason detail.\n *\n * ```javascript\n * <ui-button color=\"text\" value=\"dismiss\">Cancel</ui-button>\n * <ui-button color=\"text\" value=\"confirm\">Take action</ui-button>\n * ```\n *\n * ```javascript\n * <button value=\"dismiss\">Cancel</button>\n * <button value=\"confirm\">Take action</button>\n * ```\n *\n * The detail object of the `close` event has the following properties:\n * - cancelled - Whether the dialog was cancelled by either activating the `dismiss` button or by pressing escape.\n *\n * The `close` event is only dispatched when the user interact with the dialog. Imperative control of the\n * dialog won't trigger the close button.\n *\n * ** Full example**\n *\n * ```javascript\n * <ui-dialog modal>\n * <ui-icon slot=\"icon\" icon=\"delete\"></ui-icon>\n *\n * <span slot=\"title\">Delete photos?</span>\n * <p>This action will permanently remove the selected pictures from your account.</p>\n *\n * <ui-button color=\"text\" slot=\"button\" value=\"dismiss\" type=\"text\">Cancel</ui-button>\n * <ui-button color=\"text\" slot=\"button\" value=\"confirm\" type=\"text\">Confirm</ui-button>\n * </ui-dialog>\n * ```\n *\n * @slot - The slot for the content of the dialog.\n * @slot icon - The slot to place the dialog icon\n * @slot title - The slot to place the dialog title. Do not put elements here, just the text.\n * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`\n * buttons to automatically close the dialog.\n * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.\n */\nexport default class UiDialog extends UiElement implements TypedEvents<DialogEventMap> {\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n /**\n * Opens the dialog as modal when toggling dialog's open state.\n *\n * Setting this value after the dialog was opened has no effect.\n *\n * @attribute\n */\n @property({ type: Boolean }) accessor modal = false\n\n /**\n * Toggles visibility of the dialog.\n * Note, the dialog is opened asynchronously after the update is performed.\n * @attribute\n */\n @property({ type: Boolean }) accessor open = false\n\n /**\n * Imperative access to create a dismiss button.\n * When set this will render a dismiss button at the end of the buttons line, before the `confirmLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor dismissLabel: string | undefined\n\n /**\n * Imperative access to create a confirm button.\n * When set this will render a confirm button at the end of the buttons line, after the `dismissLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor confirmLabel: string | undefined\n\n /**\n * When true, styles the confirm button with error colors to indicate\n * a destructive action (e.g., delete, remove, etc.).\n * @attribute\n */\n @property({ type: Boolean }) accessor destructive = false\n\n /**\n * Part of the imperative access to the element.\n * When set, it wraps the content in a `<form>` element.\n * When this is enabled the following will happen:\n * - The `confirm` button will get `type=\"submit\"`\n * - The form `method` attribute is set to `dialog`\n * - The form `id` attribute is set to a random string. You can get it from the `formId` getter.\n * - The dialog will dispatch the same `submit` event as the form.\n * - When the `submit` event dispatched by the dialog gets cancelled, then:\n * - The original submit event also gets cancelled.\n * - The default confirm action is not invoked\n * - The dialog stays opened\n * - When the submit event is not cancelled, then:\n * - The default confirm action is invoked.\n * - The dialog is closed.\n *\n * @deprecated Wrap the content in a `<form>` element instead.\n */\n @property({ type: Boolean }) accessor useForm: boolean | undefined\n\n /**\n * Only when `confirmLabel` is set.\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value}\n * @attribute\n */\n @property({ type: String }) accessor confirmValue: string | undefined\n /**\n * When the dialog is wrapped in a form, set this to `true` to close the dialog\n * when the form is submitted.\n *\n * Note that the dialog doesn't perform any validation of the form. It only closes\n * when the form is submitted, regardless of the application logic. The `submit` event\n * is dispatched by the dialog when the form is valid.\n */\n @property({ type: Boolean }) accessor submitClose: boolean | undefined\n\n /**\n * A reference to the underlying dialog element.\n */\n @query('dialog') accessor dialog!: HTMLDialogElement\n\n @state() protected accessor hasIcon = false\n\n @state() protected accessor hasTitle = false\n\n @state() protected accessor hasButton = false\n\n @queryAssignedElements({ flatten: true, slot: 'icon' }) protected accessor icons!: HTMLElement[]\n\n @queryAssignedNodes({ flatten: true, slot: 'title' }) protected accessor titles!: HTMLElement[]\n\n @queryAssignedElements({ flatten: true, slot: 'button' }) protected accessor buttons!: HTMLElement[]\n\n /**\n * To be set by a child class when closing the dialog.\n * This is passed to the close event.\n */\n dialogValue?: unknown\n\n #formId?: string\n\n /**\n * @deprecated Use `useForm` instead.\n */\n get formId(): string | undefined {\n return this.#formId\n }\n\n /**\n * @deprecated This will be removed in the future.\n */\n @state() accessor #inject: TemplateResult | RenderFunction | undefined\n\n /**\n * @deprecated This will be removed in the future.\n */\n #pendingStyles?: CSSResultOrNative[]\n\n /**\n * A reference to the parent form element.\n * When a form is found, the dialog will hook into the form's submit event\n * and close the dialog when the form is submitted.\n * Since the `submit` event is dispatched when the form is valid,\n * we can use this to close the dialog and not worry about the form validation.\n */\n #form: HTMLFormElement | null = null\n\n constructor() {\n super()\n\n this.addEventListener('click', this.handleClick)\n this.addEventListener('keydown', this.handleKeyDown)\n }\n\n /**\n * Allows to inject a template into the internals of the element.\n * This is helpful when working with imperative dialogs.\n * @param content The content to inject into the body.\n * @deprecated This will be removed in the future. To use forms, wrap the content in a `<form>` element.\n */\n inject(content?: TemplateResult | RenderFunction, styles?: CSSResultOrNative[]): void {\n this.#inject = content\n if (styles) {\n if (this.shadowRoot) {\n adoptStyles(this.shadowRoot, styles)\n } else {\n if (!this.#pendingStyles) {\n this.#pendingStyles = []\n }\n this.#pendingStyles.push(...styles)\n }\n }\n if (this.shadowRoot && styles) {\n adoptStyles(this.shadowRoot, styles)\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.#form = this.closest('form')\n if (this.#form) {\n this.#form.addEventListener('submit', this.handleFormSubmit)\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n if (this.#form) {\n this.#form.removeEventListener('submit', this.handleFormSubmit)\n this.#form = null\n }\n }\n\n protected override firstUpdated(): void {\n const styles = this.#pendingStyles\n if (styles) {\n const root = this.shadowRoot as ShadowRoot\n const all = [...root.adoptedStyleSheets, ...styles]\n adoptStyles(this.shadowRoot as ShadowRoot, all)\n }\n }\n\n override willUpdate(cp: PropertyValues<this>): void {\n if (cp.has('useForm') && this.useForm && !this.#formId) {\n const r = (Math.random() + 1).toString(36).substring(7)\n this.#formId = `form-${r}`\n }\n }\n\n @bound\n protected handleFormSubmit(): void {\n if (this.submitClose) {\n this.handleInteraction('confirm')\n }\n }\n\n override handleClick(e: MouseEvent): void {\n super.handleClick(e)\n const path = e.composedPath()\n const { buttons } = this\n const button = path.find((i) => buttons.includes(i as HTMLElement)) as HTMLButtonElement | UiButton | undefined\n if (!button) {\n return\n }\n if (button.type === 'submit') {\n // Adds support for forms.\n // When a form's submit button is clicked we yield the flow control to the form.\n // This way the form can handle the submit event.\n return\n }\n const { value = '' } = button\n this.handleInteraction(value as 'dismiss' | 'confirm')\n }\n\n override handleKeyDown(e: KeyboardEvent): void {\n super.handleKeyDown(e)\n if (e.defaultPrevented) {\n return\n }\n if (e.key === 'Escape') {\n this.handleInteraction('dismiss')\n }\n }\n\n override updated(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('open')) {\n this.#controlVisibility()\n }\n super.updated(changedProperties)\n }\n\n #controlVisibility(): void {\n const { dialog, modal, open } = this\n if (!dialog) {\n return\n }\n if (open) {\n if (modal) {\n dialog.showModal()\n } else {\n dialog.show()\n }\n } else {\n dialog.close()\n }\n }\n\n #handleSlotChange(): void {\n const { icons, titles, buttons } = this\n this.hasIcon = !!icons && !!icons.length\n this.hasTitle = !!titles && !!titles.length\n this.hasButton = !!buttons && !!buttons.length\n }\n\n protected handleInteraction(value: 'dismiss' | 'confirm'): void {\n if (!['dismiss', 'confirm'].includes(value)) {\n return\n }\n this.open = false\n const detail: UiDialogClosingReason = {\n cancelled: value === 'dismiss',\n }\n if (this.dialogValue !== undefined) {\n detail.value = this.dialogValue\n }\n this.dispatchEvent(\n new CustomEvent<UiDialogClosingReason>('close', {\n composed: true,\n detail,\n })\n )\n }\n\n protected handleDialogClose(): void {\n if (!this.open) {\n return\n }\n this.open = false\n this.handleInteraction('dismiss')\n }\n\n protected handleDismiss(): void {\n this.handleInteraction('dismiss')\n }\n\n protected handleConfirm(): void {\n if (!this.useForm) {\n this.handleInteraction('confirm')\n }\n }\n\n #handleSubmit(event: SubmitEvent): void {\n const form = event.target as HTMLFormElement\n const copy = new SyntheticSubmitEvent(event.type, form, {\n submitter: event.submitter,\n cancelable: true,\n bubbles: false,\n composed: false,\n })\n const dispatched = this.dispatchEvent(copy)\n if (dispatched) {\n this.handleInteraction('confirm')\n } else {\n event.preventDefault()\n }\n }\n\n override render(): TemplateResult {\n const { useForm, modal } = this\n const dialogClass = modal ? 'modal' : 'non-modal'\n return html`\n <dialog @close=\"${this.handleDialogClose}\" part=\"dialog\" class=\"${dialogClass}\">\n <div class=\"container\">${useForm ? this.#renderFormContent() : this.renderContent()}</div>\n </dialog>\n `\n }\n\n protected renderContent(): TemplateResult[] | TemplateResult {\n return [this.renderIcon(), this.renderTitle(), this.renderBody(), this.renderButtons()]\n }\n\n #renderFormContent(): TemplateResult {\n return html`\n <form id=\"${ifDefined(this.formId)}\" method=\"dialog\" @submit=\"${this.#handleSubmit}\" part=\"form\">\n ${this.renderContent()}\n </form>\n `\n }\n\n protected renderIcon(): TemplateResult {\n const classes: ClassInfo = {\n 'icon': true,\n 'with-icon': this.hasIcon,\n 'destructive': this.destructive,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"icon\">\n <slot name=\"icon\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderTitle(): TemplateResult {\n const classes: ClassInfo = {\n 'title': true,\n 'with-title': this.hasTitle,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"title\">\n <slot name=\"title\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderBody(): TemplateResult {\n let content = this.#inject\n if (typeof content === 'function') {\n content = content()\n }\n const injected = content || nothing\n return html` <div class=\"content\" part=\"body\"><slot></slot>${injected}</div> `\n }\n\n protected renderButtons(): TemplateResult {\n const classes: ClassInfo = {\n 'buttons': true,\n 'with-buttons': this.hasButton || !!this.confirmLabel || !!this.dismissLabel,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"button\">\n <slot name=\"button\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n ${this.#renderDismissButton()} ${this.#renderConfirmButton()}\n </div>\n `\n }\n\n #renderDismissButton(): TemplateResult | typeof nothing {\n const { dismissLabel } = this\n if (!dismissLabel) {\n return nothing\n }\n return html`\n <ui-button\n color=\"text\"\n value=\"dismiss\"\n class=\"internal-button\"\n @click=\"${this.handleDismiss}\"\n part=\"negative-action\"\n >${dismissLabel}</ui-button\n >\n `\n }\n\n #renderConfirmButton(): TemplateResult | typeof nothing {\n const { confirmLabel, confirmValue = 'confirm', useForm, destructive } = this\n if (!confirmLabel) {\n return nothing\n }\n const type = useForm ? 'submit' : 'button'\n const buttonClass = destructive ? 'internal-button destructive' : 'internal-button'\n return html`\n <ui-button\n color=\"text\"\n type=\"${type}\"\n value=\"${confirmValue}\"\n class=\"${buttonClass}\"\n @click=\"${this.handleConfirm}\"\n part=\"positive-action\"\n >${confirmLabel}</ui-button\n >\n `\n }\n}\n"]}
1
+ {"version":3,"file":"Dialog.js","sourceRoot":"","sources":["../../../../../src/md/dialog/internals/Dialog.ts"],"names":[],"mappings":";AAAA,OAAO,EAA0B,IAAI,EAAE,OAAO,EAA4C,WAAW,EAAE,MAAM,KAAK,CAAA;AAClH,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACrG,OAAO,EAAkB,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAGlE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAA;AAC9E,OAAO,2BAA2B,CAAA;AAClC,OAA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EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAA;YAC7E,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,OAAO,OAAO,CAAA;YAChB,CAAC;YACD,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAA;YAC1C,MAAM,WAAW,GAAG,WAAW,CAAC,CAAC,CAAC,6BAA6B,CAAC,CAAC,CAAC,iBAAiB,CAAA;YACnF,OAAO,IAAI,CAAA;;;gBAGC,IAAI;iBACH,YAAY;iBACZ,WAAW;kBACV,IAAI,CAAC,aAAa;;WAEzB,YAAY;;KAElB,CAAA;QACH,CAAC;;;AAxgBH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAudC","sourcesContent":["import { type CSSResultOrNative, html, nothing, type PropertyValues, type TemplateResult, adoptStyles } from 'lit'\nimport { property, query, queryAssignedElements, queryAssignedNodes, state } from 'lit/decorators.js'\nimport { type ClassInfo, classMap } from 'lit/directives/class-map.js'\nimport { UiElement } from '../../UiElement.js'\nimport { isDisabled, setDisabled } from '../../../lib/disabled.js'\nimport type UiButton from '../../button/internals/button.js'\nimport type { TypedEvents } from '../../../core/types.js'\nimport { ifDefined } from 'lit/directives/if-defined.js'\nimport { SyntheticSubmitEvent } from '../../../events/SyntheticSubmitEvent.js'\nimport '../../button/ui-button.js'\nimport { bound } from '../../../decorators/bound.js'\n\nexport interface UiDialogClosingReason {\n /**\n * Whether the dialog was cancelled by either activating the `dismiss` button\n * or by pressing escape.\n */\n cancelled: boolean\n /**\n * This is used in cases when the dialog has more complex purpose.\n * This is the value expected from the dialog.\n */\n value?: unknown\n}\n\ninterface DialogEventMap {\n closing: CustomEvent<UiDialogClosingReason>\n close: CustomEvent<UiDialogClosingReason>\n}\n\nexport type RenderFunction = () => TemplateResult\n\n/**\n * Styled dialog using a native `<dialog>` element under the hood.\n * Note, since native dialog renders in the top layer it is not necessary\n * to place the dialog in the `<body>`.\n *\n * **Using Buttons**\n *\n * The dialog automatically recognizes buttons with values `confirm` and `dismiss`\n * to close the dialog and dispatch the `close` event. The event has additional\n * closing reason detail.\n *\n * ```javascript\n * <ui-button color=\"text\" value=\"dismiss\">Cancel</ui-button>\n * <ui-button color=\"text\" value=\"confirm\">Take action</ui-button>\n * ```\n *\n * ```javascript\n * <button value=\"dismiss\">Cancel</button>\n * <button value=\"confirm\">Take action</button>\n * ```\n *\n * The detail object of the `close` event has the following properties:\n * - cancelled - Whether the dialog was cancelled by either activating the `dismiss` button or by pressing escape.\n *\n * The `close` event is only dispatched when the user interact with the dialog. Imperative control of the\n * dialog won't trigger the close button.\n *\n * ** Full example**\n *\n * ```javascript\n * <ui-dialog modal>\n * <ui-icon slot=\"icon\" icon=\"delete\"></ui-icon>\n *\n * <span slot=\"title\">Delete photos?</span>\n * <p>This action will permanently remove the selected pictures from your account.</p>\n *\n * <ui-button color=\"text\" slot=\"button\" value=\"dismiss\" type=\"text\">Cancel</ui-button>\n * <ui-button color=\"text\" slot=\"button\" value=\"confirm\" type=\"text\">Confirm</ui-button>\n * </ui-dialog>\n * ```\n *\n * @slot - The slot for the content of the dialog.\n * @slot icon - The slot to place the dialog icon\n * @slot title - The slot to place the dialog title. Do not put elements here, just the text.\n * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`\n * buttons to automatically close the dialog.\n * @fires closing - A cancelable, non-bubbling event with the `UiDialogClosingReason` as the detail,\n * dispatched before the dialog closes. If prevented, the dialog will not close.\n * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.\n */\nexport default class UiDialog extends UiElement implements TypedEvents<DialogEventMap> {\n get disabled(): boolean {\n return isDisabled(this)\n }\n\n /**\n * When set, the button is a disabled state.\n * @attribute\n */\n @property({ reflect: true, type: Boolean })\n set disabled(value: boolean) {\n const old = isDisabled(this)\n setDisabled(this, value)\n this.requestUpdate('disabled', old)\n }\n\n /**\n * Opens the dialog as modal when toggling dialog's open state.\n *\n * Setting this value after the dialog was opened has no effect.\n *\n * @attribute\n */\n @property({ type: Boolean }) accessor modal = false\n\n /**\n * Toggles visibility of the dialog.\n * Note, the dialog is opened asynchronously after the update is performed.\n * @attribute\n */\n @property({ type: Boolean }) accessor open = false\n\n /**\n * Imperative access to create a dismiss button.\n * When set this will render a dismiss button at the end of the buttons line, before the `confirmLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor dismissLabel: string | undefined\n\n /**\n * Imperative access to create a confirm button.\n * When set this will render a confirm button at the end of the buttons line, after the `dismissLabel` button.\n * @attribute\n */\n @property({ type: String }) accessor confirmLabel: string | undefined\n\n /**\n * When true, styles the confirm button with error colors to indicate\n * a destructive action (e.g., delete, remove, etc.).\n * @attribute\n */\n @property({ type: Boolean }) accessor destructive = false\n\n /**\n * Part of the imperative access to the element.\n * When set, it wraps the content in a `<form>` element.\n * When this is enabled the following will happen:\n * - The `confirm` button will get `type=\"submit\"`\n * - The form `method` attribute is set to `dialog`\n * - The form `id` attribute is set to a random string. You can get it from the `formId` getter.\n * - The dialog will dispatch the same `submit` event as the form.\n * - When the `submit` event dispatched by the dialog gets cancelled, then:\n * - The original submit event also gets cancelled.\n * - The default confirm action is not invoked\n * - The dialog stays opened\n * - When the submit event is not cancelled, then:\n * - The default confirm action is invoked.\n * - The dialog is closed.\n *\n * @deprecated Wrap the content in a `<form>` element instead.\n */\n @property({ type: Boolean }) accessor useForm: boolean | undefined\n\n /**\n * Only when `confirmLabel` is set.\n * Defines the value associated with the button's name when it's submitted with the form data.\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#value}\n * @attribute\n */\n @property({ type: String }) accessor confirmValue: string | undefined\n /**\n * When the dialog is wrapped in a form, set this to `true` to close the dialog\n * when the form is submitted.\n *\n * Note that the dialog doesn't perform any validation of the form. It only closes\n * when the form is submitted, regardless of the application logic. The `submit` event\n * is dispatched by the dialog when the form is valid.\n */\n @property({ type: Boolean }) accessor submitClose: boolean | undefined\n\n /**\n * A reference to the underlying dialog element.\n */\n @query('dialog') accessor dialog!: HTMLDialogElement\n\n @state() protected accessor hasIcon = false\n\n @state() protected accessor hasTitle = false\n\n @state() protected accessor hasButton = false\n\n @queryAssignedElements({ flatten: true, slot: 'icon' }) protected accessor icons!: HTMLElement[]\n\n @queryAssignedNodes({ flatten: true, slot: 'title' }) protected accessor titles!: HTMLElement[]\n\n @queryAssignedElements({ flatten: true, slot: 'button' }) protected accessor buttons!: HTMLElement[]\n\n /**\n * To be set by a child class when closing the dialog.\n * This is passed to the close event.\n */\n dialogValue?: unknown\n\n #formId?: string\n\n /**\n * @deprecated Use `useForm` instead.\n */\n get formId(): string | undefined {\n return this.#formId\n }\n\n /**\n * @deprecated This will be removed in the future.\n */\n @state() accessor #inject: TemplateResult | RenderFunction | undefined\n\n /**\n * @deprecated This will be removed in the future.\n */\n #pendingStyles?: CSSResultOrNative[]\n\n /**\n * A reference to the parent form element.\n * When a form is found, the dialog will hook into the form's submit event\n * and close the dialog when the form is submitted.\n * Since the `submit` event is dispatched when the form is valid,\n * we can use this to close the dialog and not worry about the form validation.\n */\n #form: HTMLFormElement | null = null\n\n constructor() {\n super()\n\n this.addEventListener('click', this.handleClick)\n this.addEventListener('keydown', this.handleKeyDown)\n }\n\n /**\n * Allows to inject a template into the internals of the element.\n * This is helpful when working with imperative dialogs.\n * @param content The content to inject into the body.\n * @deprecated This will be removed in the future. To use forms, wrap the content in a `<form>` element.\n */\n inject(content?: TemplateResult | RenderFunction, styles?: CSSResultOrNative[]): void {\n this.#inject = content\n if (styles) {\n if (this.shadowRoot) {\n adoptStyles(this.shadowRoot, styles)\n } else {\n if (!this.#pendingStyles) {\n this.#pendingStyles = []\n }\n this.#pendingStyles.push(...styles)\n }\n }\n if (this.shadowRoot && styles) {\n adoptStyles(this.shadowRoot, styles)\n }\n }\n\n override connectedCallback(): void {\n super.connectedCallback()\n this.#form = this.closest('form')\n if (this.#form) {\n this.#form.addEventListener('submit', this.handleFormSubmit)\n }\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback()\n if (this.#form) {\n this.#form.removeEventListener('submit', this.handleFormSubmit)\n this.#form = null\n }\n }\n\n protected override firstUpdated(): void {\n const styles = this.#pendingStyles\n if (styles) {\n const root = this.shadowRoot as ShadowRoot\n const all = [...root.adoptedStyleSheets, ...styles]\n adoptStyles(this.shadowRoot as ShadowRoot, all)\n }\n }\n\n override willUpdate(cp: PropertyValues<this>): void {\n if (cp.has('useForm') && this.useForm && !this.#formId) {\n const r = (Math.random() + 1).toString(36).substring(7)\n this.#formId = `form-${r}`\n }\n }\n\n @bound\n protected handleFormSubmit(): void {\n if (this.submitClose) {\n this.handleInteraction('confirm')\n }\n }\n\n override handleClick(e: MouseEvent): void {\n super.handleClick(e)\n const path = e.composedPath()\n const { buttons } = this\n const button = path.find((i) => buttons.includes(i as HTMLElement)) as HTMLButtonElement | UiButton | undefined\n if (!button) {\n return\n }\n if (button.type === 'submit') {\n // Adds support for forms.\n // When a form's submit button is clicked we yield the flow control to the form.\n // This way the form can handle the submit event.\n return\n }\n const { value = '' } = button\n this.handleInteraction(value as 'dismiss' | 'confirm')\n }\n\n override handleKeyDown(e: KeyboardEvent): void {\n super.handleKeyDown(e)\n if (e.defaultPrevented) {\n return\n }\n if (e.key === 'Escape') {\n this.handleInteraction('dismiss')\n }\n }\n\n override updated(changedProperties: PropertyValues<this>): void {\n if (changedProperties.has('open')) {\n this.#controlVisibility()\n }\n super.updated(changedProperties)\n }\n\n #controlVisibility(): void {\n const { dialog, modal, open } = this\n if (!dialog) {\n return\n }\n if (open) {\n if (modal) {\n dialog.showModal()\n } else {\n dialog.show()\n }\n } else {\n dialog.close()\n }\n }\n\n #handleSlotChange(): void {\n const { icons, titles, buttons } = this\n this.hasIcon = !!icons && !!icons.length\n this.hasTitle = !!titles && !!titles.length\n this.hasButton = !!buttons && !!buttons.length\n }\n\n protected handleInteraction(value: 'dismiss' | 'confirm'): void {\n if (!['dismiss', 'confirm'].includes(value)) {\n return\n }\n\n const detail: UiDialogClosingReason = {\n cancelled: value === 'dismiss',\n }\n if (this.dialogValue !== undefined) {\n detail.value = this.dialogValue\n }\n\n // Dispatch cancelable closing event first\n const closingEvent = new CustomEvent<UiDialogClosingReason>('closing', {\n cancelable: true,\n composed: false,\n bubbles: false,\n detail,\n })\n const canClose = this.dispatchEvent(closingEvent)\n\n // Only proceed with closing if the event wasn't canceled\n if (!canClose) {\n return\n }\n\n this.open = false\n this.dispatchEvent(\n new CustomEvent<UiDialogClosingReason>('close', {\n composed: true,\n detail,\n })\n )\n }\n\n protected handleDialogClose(): void {\n if (!this.open) {\n return\n }\n\n const detail: UiDialogClosingReason = {\n cancelled: true,\n }\n if (this.dialogValue !== undefined) {\n detail.value = this.dialogValue\n }\n\n // Dispatch cancelable closing event first\n const closingEvent = new CustomEvent<UiDialogClosingReason>('closing', {\n cancelable: true,\n composed: false,\n bubbles: false,\n detail,\n })\n const canClose = this.dispatchEvent(closingEvent)\n\n // Only proceed with closing if the event wasn't canceled\n if (!canClose) {\n // If closing was prevented, reopen the dialog\n this.dialog.showModal()\n return\n }\n\n this.open = false\n this.dispatchEvent(\n new CustomEvent<UiDialogClosingReason>('close', {\n composed: true,\n detail,\n })\n )\n }\n\n protected handleDismiss(): void {\n this.handleInteraction('dismiss')\n }\n\n protected handleConfirm(): void {\n if (!this.useForm) {\n this.handleInteraction('confirm')\n }\n }\n\n #handleSubmit(event: SubmitEvent): void {\n const form = event.target as HTMLFormElement\n const copy = new SyntheticSubmitEvent(event.type, form, {\n submitter: event.submitter,\n cancelable: true,\n bubbles: false,\n composed: false,\n })\n const dispatched = this.dispatchEvent(copy)\n if (dispatched) {\n this.handleInteraction('confirm')\n } else {\n event.preventDefault()\n }\n }\n\n override render(): TemplateResult {\n const { useForm, modal } = this\n const dialogClass = modal ? 'modal' : 'non-modal'\n return html`\n <dialog @close=\"${this.handleDialogClose}\" part=\"dialog\" class=\"${dialogClass}\">\n <div class=\"container\">${useForm ? this.#renderFormContent() : this.renderContent()}</div>\n </dialog>\n `\n }\n\n protected renderContent(): TemplateResult[] | TemplateResult {\n return [this.renderIcon(), this.renderTitle(), this.renderBody(), this.renderButtons()]\n }\n\n #renderFormContent(): TemplateResult {\n return html`\n <form id=\"${ifDefined(this.formId)}\" method=\"dialog\" @submit=\"${this.#handleSubmit}\" part=\"form\">\n ${this.renderContent()}\n </form>\n `\n }\n\n protected renderIcon(): TemplateResult {\n const classes: ClassInfo = {\n 'icon': true,\n 'with-icon': this.hasIcon,\n 'destructive': this.destructive,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"icon\">\n <slot name=\"icon\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderTitle(): TemplateResult {\n const classes: ClassInfo = {\n 'title': true,\n 'with-title': this.hasTitle,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"title\">\n <slot name=\"title\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n </div>\n `\n }\n\n protected renderBody(): TemplateResult {\n let content = this.#inject\n if (typeof content === 'function') {\n content = content()\n }\n const injected = content || nothing\n return html` <div class=\"content\" part=\"body\"><slot></slot>${injected}</div> `\n }\n\n protected renderButtons(): TemplateResult {\n const classes: ClassInfo = {\n 'buttons': true,\n 'with-buttons': this.hasButton || !!this.confirmLabel || !!this.dismissLabel,\n }\n return html`\n <div class=\"${classMap(classes)}\" part=\"button\">\n <slot name=\"button\" @slotchange=\"${this.#handleSlotChange}\"></slot>\n ${this.#renderDismissButton()} ${this.#renderConfirmButton()}\n </div>\n `\n }\n\n #renderDismissButton(): TemplateResult | typeof nothing {\n const { dismissLabel } = this\n if (!dismissLabel) {\n return nothing\n }\n return html`\n <ui-button\n color=\"text\"\n value=\"dismiss\"\n class=\"internal-button\"\n @click=\"${this.handleDismiss}\"\n part=\"negative-action\"\n >${dismissLabel}</ui-button\n >\n `\n }\n\n #renderConfirmButton(): TemplateResult | typeof nothing {\n const { confirmLabel, confirmValue = 'confirm', useForm, destructive } = this\n if (!confirmLabel) {\n return nothing\n }\n const type = useForm ? 'submit' : 'button'\n const buttonClass = destructive ? 'internal-button destructive' : 'internal-button'\n return html`\n <ui-button\n color=\"text\"\n type=\"${type}\"\n value=\"${confirmValue}\"\n class=\"${buttonClass}\"\n @click=\"${this.handleConfirm}\"\n part=\"positive-action\"\n >${confirmLabel}</ui-button\n >\n `\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@api-client/ui",
3
- "version": "0.5.18",
3
+ "version": "0.5.19",
4
4
  "description": "Internal UI component library for the API Client ecosystem.",
5
5
  "license": "UNLICENSED",
6
6
  "main": "build/src/index.js",
@@ -24,6 +24,7 @@ export interface UiDialogClosingReason {
24
24
  }
25
25
 
26
26
  interface DialogEventMap {
27
+ closing: CustomEvent<UiDialogClosingReason>
27
28
  close: CustomEvent<UiDialogClosingReason>
28
29
  }
29
30
 
@@ -75,6 +76,8 @@ export type RenderFunction = () => TemplateResult
75
76
  * @slot title - The slot to place the dialog title. Do not put elements here, just the text.
76
77
  * @slot button - The slot to place the dialog buttons. Use the `confirm` or `dismiss`
77
78
  * buttons to automatically close the dialog.
79
+ * @fires closing - A cancelable, non-bubbling event with the `UiDialogClosingReason` as the detail,
80
+ * dispatched before the dialog closes. If prevented, the dialog will not close.
78
81
  * @fires close - A non-bubbling, non-cancellable event with the `UiDialogClosingReason` as the detail.
79
82
  */
80
83
  export default class UiDialog extends UiElement implements TypedEvents<DialogEventMap> {
@@ -349,13 +352,29 @@ export default class UiDialog extends UiElement implements TypedEvents<DialogEve
349
352
  if (!['dismiss', 'confirm'].includes(value)) {
350
353
  return
351
354
  }
352
- this.open = false
355
+
353
356
  const detail: UiDialogClosingReason = {
354
357
  cancelled: value === 'dismiss',
355
358
  }
356
359
  if (this.dialogValue !== undefined) {
357
360
  detail.value = this.dialogValue
358
361
  }
362
+
363
+ // Dispatch cancelable closing event first
364
+ const closingEvent = new CustomEvent<UiDialogClosingReason>('closing', {
365
+ cancelable: true,
366
+ composed: false,
367
+ bubbles: false,
368
+ detail,
369
+ })
370
+ const canClose = this.dispatchEvent(closingEvent)
371
+
372
+ // Only proceed with closing if the event wasn't canceled
373
+ if (!canClose) {
374
+ return
375
+ }
376
+
377
+ this.open = false
359
378
  this.dispatchEvent(
360
379
  new CustomEvent<UiDialogClosingReason>('close', {
361
380
  composed: true,
@@ -368,8 +387,37 @@ export default class UiDialog extends UiElement implements TypedEvents<DialogEve
368
387
  if (!this.open) {
369
388
  return
370
389
  }
390
+
391
+ const detail: UiDialogClosingReason = {
392
+ cancelled: true,
393
+ }
394
+ if (this.dialogValue !== undefined) {
395
+ detail.value = this.dialogValue
396
+ }
397
+
398
+ // Dispatch cancelable closing event first
399
+ const closingEvent = new CustomEvent<UiDialogClosingReason>('closing', {
400
+ cancelable: true,
401
+ composed: false,
402
+ bubbles: false,
403
+ detail,
404
+ })
405
+ const canClose = this.dispatchEvent(closingEvent)
406
+
407
+ // Only proceed with closing if the event wasn't canceled
408
+ if (!canClose) {
409
+ // If closing was prevented, reopen the dialog
410
+ this.dialog.showModal()
411
+ return
412
+ }
413
+
371
414
  this.open = false
372
- this.handleInteraction('dismiss')
415
+ this.dispatchEvent(
416
+ new CustomEvent<UiDialogClosingReason>('close', {
417
+ composed: true,
418
+ detail,
419
+ })
420
+ )
373
421
  }
374
422
 
375
423
  protected handleDismiss(): void {
@@ -441,5 +441,319 @@ describe('md', () => {
441
441
  })
442
442
  })
443
443
  })
444
+
445
+ describe('closing event', () => {
446
+ it('dispatches the closing event before close event when dismissing', async () => {
447
+ const element = await buttonFixture()
448
+ const closingSpy = sinon.spy()
449
+ const closeSpy = sinon.spy()
450
+ element.addEventListener('closing', closingSpy)
451
+ element.addEventListener('close', closeSpy)
452
+
453
+ const button = element.querySelector('ui-button[value="dismiss"]') as UiButton
454
+ button.click()
455
+
456
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
457
+ assert.isTrue(closeSpy.calledOnce, 'close event was dispatched')
458
+ assert.isTrue(closingSpy.calledBefore(closeSpy), 'closing event was dispatched before close event')
459
+ })
460
+
461
+ it('dispatches the closing event before close event when confirming', async () => {
462
+ const element = await buttonFixture()
463
+ const closingSpy = sinon.spy()
464
+ const closeSpy = sinon.spy()
465
+ element.addEventListener('closing', closingSpy)
466
+ element.addEventListener('close', closeSpy)
467
+
468
+ const button = element.querySelector('ui-button[value="confirm"]') as UiButton
469
+ button.click()
470
+
471
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
472
+ assert.isTrue(closeSpy.calledOnce, 'close event was dispatched')
473
+ assert.isTrue(closingSpy.calledBefore(closeSpy), 'closing event was dispatched before close event')
474
+ })
475
+
476
+ it('dispatches the closing event when pressing Escape', async () => {
477
+ const element = await buttonFixture()
478
+ const closingSpy = sinon.spy()
479
+ const closeSpy = sinon.spy()
480
+ element.addEventListener('closing', closingSpy)
481
+ element.addEventListener('close', closeSpy)
482
+
483
+ element.open = true
484
+ await element.updateComplete
485
+ const button = element.querySelector('ui-button')!
486
+ button.focus()
487
+ await UiMock.keyPress(element, 'Escape', { key: 'Escape' })
488
+
489
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
490
+ assert.isTrue(closeSpy.calledOnce, 'close event was dispatched')
491
+ assert.isTrue(closingSpy.calledBefore(closeSpy), 'closing event was dispatched before close event')
492
+ })
493
+
494
+ it('dispatches the closing event with correct detail for dismiss action', async () => {
495
+ const element = await buttonFixture()
496
+ const closingSpy = sinon.spy()
497
+ element.addEventListener('closing', closingSpy)
498
+
499
+ const button = element.querySelector('ui-button[value="dismiss"]') as UiButton
500
+ button.click()
501
+
502
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
503
+ const event = closingSpy.args[0][0] as CustomEvent<UiDialogClosingReason>
504
+ assert.isTrue(event.detail.cancelled, 'cancelled flag is true for dismiss action')
505
+ assert.isUndefined(event.detail.value, 'value is undefined when no dialogValue is set')
506
+ })
507
+
508
+ it('dispatches the closing event with correct detail for confirm action', async () => {
509
+ const element = await buttonFixture()
510
+ const closingSpy = sinon.spy()
511
+ element.addEventListener('closing', closingSpy)
512
+
513
+ const button = element.querySelector('ui-button[value="confirm"]') as UiButton
514
+ button.click()
515
+
516
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
517
+ const event = closingSpy.args[0][0] as CustomEvent<UiDialogClosingReason>
518
+ assert.isFalse(event.detail.cancelled, 'cancelled flag is false for confirm action')
519
+ assert.isUndefined(event.detail.value, 'value is undefined when no dialogValue is set')
520
+ })
521
+
522
+ it('includes dialogValue in closing event detail', async () => {
523
+ const element = await buttonFixture()
524
+ element.dialogValue = 'test-value'
525
+ const closingSpy = sinon.spy()
526
+ element.addEventListener('closing', closingSpy)
527
+
528
+ const button = element.querySelector('ui-button[value="confirm"]') as UiButton
529
+ button.click()
530
+
531
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
532
+ const event = closingSpy.args[0][0] as CustomEvent<UiDialogClosingReason>
533
+ assert.equal(event.detail.value, 'test-value', 'dialogValue is included in event detail')
534
+ })
535
+
536
+ it('prevents dialog closing when closing event is cancelled', async () => {
537
+ const element = await buttonFixture()
538
+ const closingSpy = sinon.spy()
539
+ const closeSpy = sinon.spy()
540
+
541
+ element.addEventListener('closing', (event) => {
542
+ closingSpy()
543
+ event.preventDefault() // Cancel the closing
544
+ })
545
+ element.addEventListener('close', closeSpy)
546
+
547
+ element.open = true
548
+ await element.updateComplete
549
+ assert.isTrue(element.open, 'dialog is initially open')
550
+
551
+ const button = element.querySelector('ui-button[value="dismiss"]') as UiButton
552
+ button.click()
553
+
554
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
555
+ assert.isFalse(closeSpy.called, 'close event was not dispatched')
556
+ assert.isTrue(element.open, 'dialog remains open when closing is prevented')
557
+ })
558
+
559
+ it('prevents dialog closing when confirming and closing event is cancelled', async () => {
560
+ const element = await buttonFixture()
561
+ const closingSpy = sinon.spy()
562
+ const closeSpy = sinon.spy()
563
+
564
+ element.addEventListener('closing', (event) => {
565
+ closingSpy()
566
+ event.preventDefault() // Cancel the closing
567
+ })
568
+ element.addEventListener('close', closeSpy)
569
+
570
+ element.open = true
571
+ await element.updateComplete
572
+ assert.isTrue(element.open, 'dialog is initially open')
573
+
574
+ const button = element.querySelector('ui-button[value="confirm"]') as UiButton
575
+ button.click()
576
+
577
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
578
+ assert.isFalse(closeSpy.called, 'close event was not dispatched')
579
+ assert.isTrue(element.open, 'dialog remains open when closing is prevented')
580
+ })
581
+
582
+ it('prevents dialog closing when pressing Escape and closing event is cancelled', async () => {
583
+ const element = await buttonFixture()
584
+ const closingSpy = sinon.spy()
585
+ const closeSpy = sinon.spy()
586
+
587
+ element.addEventListener('closing', (event) => {
588
+ closingSpy()
589
+ event.preventDefault() // Cancel the closing
590
+ })
591
+ element.addEventListener('close', closeSpy)
592
+
593
+ element.open = true
594
+ await element.updateComplete
595
+ assert.isTrue(element.open, 'dialog is initially open')
596
+
597
+ const button = element.querySelector('ui-button')!
598
+ button.focus()
599
+ await UiMock.keyPress(element, 'Escape', { key: 'Escape' })
600
+
601
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
602
+ assert.isFalse(closeSpy.called, 'close event was not dispatched')
603
+ assert.isTrue(element.open, 'dialog remains open when closing is prevented')
604
+ })
605
+
606
+ it('prevents native dialog close and reopens when closing event is cancelled', async () => {
607
+ const element = await modalFixture()
608
+ const closingSpy = sinon.spy()
609
+ const showModalSpy = sinon.spy(element.dialog, 'showModal')
610
+
611
+ element.addEventListener('closing', (event) => {
612
+ closingSpy()
613
+ event.preventDefault() // Cancel the closing
614
+ })
615
+
616
+ element.open = true
617
+ await element.updateComplete
618
+ assert.isTrue(element.open, 'dialog is initially open')
619
+ assert.isTrue(element.dialog.open, 'native dialog is open')
620
+
621
+ // Reset the spy count after initial open
622
+ showModalSpy.resetHistory()
623
+
624
+ // Simulate native dialog close event (e.g., clicking backdrop)
625
+ element.dialog.dispatchEvent(new Event('close'))
626
+
627
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
628
+ assert.isTrue(element.open, 'dialog remains open when closing is prevented')
629
+ assert.isTrue(showModalSpy.calledOnce, 'showModal was called to reopen the dialog')
630
+ })
631
+
632
+ it('verifies closing event properties', async () => {
633
+ const element = await buttonFixture()
634
+ let closingEvent: CustomEvent<UiDialogClosingReason>
635
+
636
+ element.addEventListener('closing', (event) => {
637
+ closingEvent = event as CustomEvent<UiDialogClosingReason>
638
+ })
639
+
640
+ const button = element.querySelector('ui-button[value="dismiss"]') as UiButton
641
+ button.click()
642
+
643
+ assert.isDefined(closingEvent!, 'closing event was dispatched')
644
+ assert.isTrue(closingEvent!.cancelable, 'closing event is cancelable')
645
+ assert.isFalse(closingEvent!.bubbles, 'closing event does not bubble')
646
+ assert.isFalse(closingEvent!.composed, 'closing event is not composed')
647
+ assert.equal(closingEvent!.type, 'closing', 'event type is "closing"')
648
+ })
649
+
650
+ it('works with imperative dismiss and confirm buttons', async () => {
651
+ const element = await basicFixture()
652
+ element.dismissLabel = 'Cancel'
653
+ element.confirmLabel = 'OK'
654
+ await element.updateComplete
655
+
656
+ const closingSpy = sinon.spy()
657
+ const closeSpy = sinon.spy()
658
+ element.addEventListener('closing', closingSpy)
659
+ element.addEventListener('close', closeSpy)
660
+
661
+ // Test dismiss button
662
+ const dismissButton = element.shadowRoot!.querySelector('.internal-button[value="dismiss"]') as UiButton
663
+ dismissButton.click()
664
+
665
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched for dismiss')
666
+ assert.isTrue(closeSpy.calledOnce, 'close event was dispatched for dismiss')
667
+
668
+ // Reset spies and test confirm button
669
+ closingSpy.resetHistory()
670
+ closeSpy.resetHistory()
671
+ element.open = true
672
+ await element.updateComplete
673
+
674
+ const confirmButton = element.shadowRoot!.querySelector('.internal-button[value="confirm"]') as UiButton
675
+ confirmButton.click()
676
+
677
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched for confirm')
678
+ assert.isTrue(closeSpy.calledOnce, 'close event was dispatched for confirm')
679
+ })
680
+
681
+ it('can prevent closing with imperative buttons', async () => {
682
+ const element = await basicFixture()
683
+ element.dismissLabel = 'Cancel'
684
+ await element.updateComplete
685
+
686
+ const closingSpy = sinon.spy()
687
+ const closeSpy = sinon.spy()
688
+
689
+ element.addEventListener('closing', (event) => {
690
+ closingSpy()
691
+ event.preventDefault()
692
+ })
693
+ element.addEventListener('close', closeSpy)
694
+
695
+ element.open = true
696
+ await element.updateComplete
697
+
698
+ const dismissButton = element.shadowRoot!.querySelector('.internal-button[value="dismiss"]') as UiButton
699
+ dismissButton.click()
700
+
701
+ assert.isTrue(closingSpy.calledOnce, 'closing event was dispatched')
702
+ assert.isFalse(closeSpy.called, 'close event was not dispatched')
703
+ assert.isTrue(element.open, 'dialog remains open')
704
+ })
705
+ })
706
+
707
+ describe('accessibility', () => {
708
+ it('meets accessibility standards in closed state', async () => {
709
+ const element = await basicFixture()
710
+ await assert.isAccessible(element)
711
+ })
712
+
713
+ it('meets accessibility standards when open', async () => {
714
+ const element = await basicFixture()
715
+ element.open = true
716
+ await element.updateComplete
717
+ await assert.isAccessible(element)
718
+ })
719
+
720
+ it('meets accessibility standards with modal dialog', async () => {
721
+ const element = await modalFixture()
722
+ element.open = true
723
+ await element.updateComplete
724
+ await assert.isAccessible(element)
725
+ })
726
+
727
+ it('meets accessibility standards with full content', async () => {
728
+ const element: UiDialog = await fixture(html`
729
+ <ui-dialog modal open>
730
+ <ui-icon slot="icon" icon="deleteOutline"></ui-icon>
731
+ <span slot="title">Delete confirmation</span>
732
+ <p>Are you sure you want to delete this item?</p>
733
+ <ui-button color="text" slot="button" value="dismiss">Cancel</ui-button>
734
+ <ui-button color="text" slot="button" value="confirm">Delete</ui-button>
735
+ </ui-dialog>
736
+ `)
737
+ await element.updateComplete
738
+ await assert.isAccessible(element)
739
+ })
740
+
741
+ it('maintains accessibility when closing is prevented', async () => {
742
+ const element = await buttonFixture()
743
+ element.addEventListener('closing', (event) => {
744
+ event.preventDefault()
745
+ })
746
+
747
+ element.open = true
748
+ await element.updateComplete
749
+
750
+ const button = element.querySelector('ui-button[value="dismiss"]') as UiButton
751
+ button.click()
752
+
753
+ // Dialog should remain open and accessible
754
+ assert.isTrue(element.open, 'dialog remains open')
755
+ await assert.isAccessible(element)
756
+ })
757
+ })
444
758
  })
445
759
  })