diff --git a/packages/beeq/src/components/dialog/_storybook/bq-dialog.stories.tsx b/packages/beeq/src/components/dialog/_storybook/bq-dialog.stories.tsx
index d3682107e..85fbbb44a 100644
--- a/packages/beeq/src/components/dialog/_storybook/bq-dialog.stories.tsx
+++ b/packages/beeq/src/components/dialog/_storybook/bq-dialog.stories.tsx
@@ -1,5 +1,6 @@
import type { Args, Meta, StoryObj } from '@storybook/web-components';
import { html, nothing } from 'lit-html';
+import { ifDefined } from 'lit-html/directives/if-defined.js';
import mdx from './bq-dialog.mdx';
import { DIALOG_BORDER_RADIUS, DIALOG_FOOTER_APPEARANCE, DIALOG_SIZE } from '../bq-dialog.types';
@@ -30,6 +31,7 @@ const meta: Meta = {
// Not part of the public API
noContent: { control: 'boolean', table: { disable: true } },
noFooter: { control: 'boolean', table: { disable: true } },
+ customClose: { control: 'text', table: { disable: true } },
},
args: {
'disable-backdrop': false,
@@ -73,6 +75,7 @@ const Template = (args: Args) => {
@bqAfterOpen=${args.bqAfterOpen}
@bqAfterClose=${args.bqAfterClose}
>
+ ${ifDefined(args.customClose)}
Title
@@ -130,6 +133,29 @@ export const NoBackdrop: Story = {
},
};
+export const CustomCloseButton: Story = {
+ render: Template,
+ args: {
+ open: true,
+ customClose: html`
+
+
+
+
+ `,
+ },
+};
+
const ConfirmTemplate = (args: Args) => {
const handleOpenDialog = async () => {
const dialogElem = document.querySelector('bq-dialog');
diff --git a/packages/beeq/src/components/dialog/bq-dialog.tsx b/packages/beeq/src/components/dialog/bq-dialog.tsx
index 25ffeca63..fc3872fe1 100644
--- a/packages/beeq/src/components/dialog/bq-dialog.tsx
+++ b/packages/beeq/src/components/dialog/bq-dialog.tsx
@@ -31,6 +31,7 @@ export class BqDialog {
private dialogElem: HTMLDialogElement;
private contentElem: HTMLElement;
private footerElem: HTMLElement;
+ private closeSlotElem: HTMLElement;
private OPEN_CSS_CLASS = 'bq-dialog--open';
// Reference to host HTML element
@@ -119,6 +120,12 @@ export class BqDialog {
componentDidLoad() {
this.handleOpenChange();
+ this.closeSlotElem = this.el.shadowRoot.querySelector('slot[name="button-close"]');
+ this.closeSlotElem?.addEventListener('click', () => this.hide());
+ }
+
+ disconnectedCallback() {
+ this.closeSlotElem?.removeEventListener('click', () => this.hide());
}
// Listeners
@@ -197,8 +204,8 @@ export class BqDialog {
private handleClose = async () => {
if (!this.dialogElem) return;
- this.dialogElem.close();
await leave(this.dialogElem);
+ this.dialogElem.close();
// Emit bqAfterClose event after the dialog is closed
this.handleTransitionEnd();
};
@@ -244,37 +251,40 @@ export class BqDialog {
return (