this.requestClose('close-button')}"
>
`
diff --git a/src/components/drawer/drawer.ts b/src/components/drawer/drawer.ts
index 5bf0cf0a..3319b70f 100644
--- a/src/components/drawer/drawer.ts
+++ b/src/components/drawer/drawer.ts
@@ -33,9 +33,10 @@ const hasPreventScroll = isPreventScrollSupported();
* @event sl-after-hide - Emitted after the drawer closes and all animations are complete.
* @event sl-initial-focus - Emitted when the drawer opens and the panel gains focus. Calling `event.preventDefault()` will
* prevent focus and allow you to set it on a different element in the drawer, such as an input or button.
- * @event sl-request-close - Emitted when the user attempts to close the drawer by clicking the close button, clicking the
- * overlay, or pressing the escape key. Calling `event.preventDefault()` will prevent the drawer from closing. Avoid
- * using this unless closing the drawer will result in destructive behavior such as data loss.
+ * @event {{ source: 'close-button' | 'keyboard' | 'overlay' }} sl-request-close - Emitted when the user attempts to
+ * close the drawer by clicking the close button, clicking the overlay, or pressing escape. Calling
+ * `event.preventDefault()` will keep the drawer open. Avoid using this unless closing the drawer will result in
+ * destructive behavior such as data loss.
*
* @csspart base - The component's base wrapper.
* @csspart overlay - The overlay.
@@ -140,8 +141,12 @@ export default class SlDrawer extends LitElement {
return waitForEvent(this, 'sl-after-hide');
}
- private requestClose() {
- const slRequestClose = emit(this, 'sl-request-close', { cancelable: true });
+ private requestClose(source: 'close-button' | 'keyboard' | 'overlay') {
+ const slRequestClose = emit(this, 'sl-request-close', {
+ cancelable: true,
+ detail: { source }
+ });
+
if (slRequestClose.defaultPrevented) {
const animation = getAnimation(this, 'drawer.denyClose');
animateTo(this.panel, animation.keyframes, animation.options);
@@ -154,7 +159,7 @@ export default class SlDrawer extends LitElement {
handleKeyDown(event: KeyboardEvent) {
if (event.key === 'Escape') {
event.stopPropagation();
- this.requestClose();
+ this.requestClose('keyboard');
}
}
@@ -243,7 +248,7 @@ export default class SlDrawer extends LitElement {
})}
@keydown=${this.handleKeyDown}
>
-
+
this.requestClose('overlay')} tabindex="-1">
this.requestClose('close-button')}
>
`