From 40ea444c4832f41e8bfbe28e885371526ba9aed4 Mon Sep 17 00:00:00 2001 From: Cory LaViska Date: Thu, 15 May 2025 12:10:49 -0400 Subject: [PATCH] add slot detection back to drawer; #928 (#931) * add slot detection back to drawer; #928 * remove unneeded attribute --- docs/docs/components/drawer.md | 19 ++++++++++--------- docs/docs/resources/changelog.md | 2 +- docs/docs/themes/edit/index.njk | 2 +- src/components/dialog/dialog.css | 8 ++++---- src/components/dialog/dialog.ts | 4 +--- src/components/drawer/drawer.css | 24 ++++++++++++------------ src/components/drawer/drawer.ts | 30 ++++++++++++++++-------------- 7 files changed, 45 insertions(+), 44 deletions(-) diff --git a/docs/docs/components/drawer.md b/docs/docs/components/drawer.md index e5927f955..80a499fad 100644 --- a/docs/docs/components/drawer.md +++ b/docs/docs/components/drawer.md @@ -8,7 +8,7 @@ icon: drawer ```html {.example} - + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Close @@ -16,7 +16,7 @@ icon: drawer Open Drawer ``` -### Customizing Initial Focus +### Setting Initial Focus -By default, the drawer's panel will gain focus when opened. This allows a subsequent tab press to focus on the first tabbable element in the drawer. If you want a different element to have focus, add the `autofocus` attribute to it as shown below. +To give focus to a specific element when the drawer opens, use the `autofocus` attribute. ```html {.example} diff --git a/docs/docs/resources/changelog.md b/docs/docs/resources/changelog.md index 510684dfb..3ed29ceca 100644 --- a/docs/docs/resources/changelog.md +++ b/docs/docs/resources/changelog.md @@ -15,7 +15,7 @@ During the alpha period, things might break! We take breaking changes very serio ## Next - 🚨 BREAKING: Renamed `` to `` and improved compatibility for non-image content -- 🚨 BREAKING: Added slot detection to `` so you don't need to specify `with-header` and `with-footer`; headers are on by default now, but you can use the `without-header` attribute to turn them off +- 🚨 BREAKING: Added slot detection to `` and `` so you don't need to specify `with-header` and `with-footer`; headers are on by default now, but you can use the `without-header` attribute to turn them off - Added support for Duotone Thin, Light, and Regular styles and the Sharp Duotone family of styles to `` - Fixed a bug that caused `` to have an undesired margin below it - Fixed a bug in the Matter theme that prevented clicks on form control labels to not focus the control diff --git a/docs/docs/themes/edit/index.njk b/docs/docs/themes/edit/index.njk index 9f5ec9b7d..7113a2c0e 100644 --- a/docs/docs/themes/edit/index.njk +++ b/docs/docs/themes/edit/index.njk @@ -38,7 +38,7 @@ unlisted: true Code - + CSS diff --git a/src/components/dialog/dialog.css b/src/components/dialog/dialog.css index b4004d43b..f7eb0a332 100644 --- a/src/components/dialog/dialog.css +++ b/src/components/dialog/dialog.css @@ -63,7 +63,7 @@ } } -.dialog--open { +.open { display: flex; opacity: 1; } @@ -128,9 +128,9 @@ .dialog::backdrop { /* - NOTE: the ::backdrop element doesn't inherit properly in Safari yet, but it will in 17.4! At that time, we can - remove the fallback values here. - */ + NOTE: the ::backdrop element doesn't inherit properly in Safari yet, but it will in 17.4! At that time, we can + remove the fallback values here. + */ background-color: var(--wa-color-overlay-modal, rgb(0 0 0 / 0.25)); } diff --git a/src/components/dialog/dialog.ts b/src/components/dialog/dialog.ts index aaa61f48d..26f4dd9f1 100644 --- a/src/components/dialog/dialog.ts +++ b/src/components/dialog/dialog.ts @@ -220,9 +220,7 @@ export default class WaDialog extends WebAwesomeElement { part="dialog" class=${classMap({ dialog: true, - 'dialog--open': this.open, - 'dialog--has-header': hasHeader, - 'dialog--has-footer': hasFooter, + open: this.open, })} @cancel=${this.handleDialogCancel} @click=${this.handleDialogClick} diff --git a/src/components/drawer/drawer.css b/src/components/drawer/drawer.css index 30a45c1fe..93daf0e26 100644 --- a/src/components/drawer/drawer.css +++ b/src/components/drawer/drawer.css @@ -40,15 +40,15 @@ animation: show-backdrop var(--hide-duration, 200ms) ease reverse; } - &.show.drawer--top { + &.show.top { animation: show-drawer-from-top var(--show-duration) ease; } - &.hide.drawer--top { + &.hide.top { animation: show-drawer-from-top var(--hide-duration) ease reverse; } - &.show.drawer--end { + &.show.end { animation: show-drawer-from-end var(--show-duration) ease; &:dir(rtl) { @@ -56,7 +56,7 @@ } } - &.hide.drawer--end { + &.hide.end { animation: show-drawer-from-end var(--hide-duration) ease reverse; &:dir(rtl) { @@ -64,15 +64,15 @@ } } - &.show.drawer--bottom { + &.show.bottom { animation: show-drawer-from-bottom var(--show-duration) ease; } - &.hide.drawer--bottom { + &.hide.bottom { animation: show-drawer-from-bottom var(--hide-duration) ease reverse; } - &.show.drawer--start { + &.show.start { animation: show-drawer-from-start var(--show-duration) ease; &:dir(rtl) { @@ -80,7 +80,7 @@ } } - &.hide.drawer--start { + &.hide.start { animation: show-drawer-from-start var(--hide-duration) ease reverse; &:dir(rtl) { @@ -97,7 +97,7 @@ outline: none; } -.drawer--top { +.top { top: 0; inset-inline-end: auto; bottom: auto; @@ -106,7 +106,7 @@ height: var(--size); } -.drawer--end { +.end { top: 0; inset-inline-end: 0; bottom: auto; @@ -115,7 +115,7 @@ height: 100%; } -.drawer--bottom { +.bottom { top: auto; inset-inline-end: auto; bottom: 0; @@ -124,7 +124,7 @@ height: var(--size); } -.drawer--start { +.start { top: 0; inset-inline-end: auto; bottom: auto; diff --git a/src/components/drawer/drawer.ts b/src/components/drawer/drawer.ts index cf5b0d9b9..a32bf731e 100644 --- a/src/components/drawer/drawer.ts +++ b/src/components/drawer/drawer.ts @@ -7,6 +7,7 @@ import { WaHideEvent } from '../../events/hide.js'; import { WaShowEvent } from '../../events/show.js'; import { animateWithClass } from '../../internal/animate.js'; import { lockBodyScrolling, unlockBodyScrolling } from '../../internal/scroll.js'; +import { HasSlotController } from '../../internal/slot.js'; import { watch } from '../../internal/watch.js'; import WebAwesomeElement from '../../internal/webawesome-element.js'; import { LocalizeController } from '../../utilities/localize.js'; @@ -61,6 +62,7 @@ export default class WaDrawer extends WebAwesomeElement { static shadowStyle = styles; private readonly localize = new LocalizeController(this); + private readonly hasSlotController = new HasSlotController(this, 'footer', 'header-actions', 'label'); private originalTrigger: HTMLElement | null; @query('.drawer') drawer: HTMLDialogElement; @@ -80,11 +82,8 @@ export default class WaDrawer extends WebAwesomeElement { /** The direction from which the drawer will open. */ @property({ reflect: true }) placement: 'top' | 'end' | 'bottom' | 'start' = 'end'; - /** Renders the drawer with a header. */ - @property({ attribute: 'with-header', type: Boolean, reflect: true }) withHeader = false; - - /** Renders the drawer with a footer. */ - @property({ attribute: 'with-footer', type: Boolean, reflect: true }) withFooter = false; + /** Disables the header. This will also remove the default close button. */ + @property({ attribute: 'without-header', type: Boolean, reflect: true }) withoutHeader = false; /** When enabled, the drawer will be closed when the user clicks outside of it. */ @property({ attribute: 'light-dismiss', type: Boolean }) lightDismiss = true; @@ -223,24 +222,27 @@ export default class WaDrawer extends WebAwesomeElement { } render() { + const hasHeader = + !this.withoutHeader && + (this.label.length > 0 || this.hasSlotController.test('label') || this.hasSlotController.test('header-actions')); + const hasFooter = this.hasSlotController.test('footer'); + return html` - ${this.withHeader + ${hasHeader ? html`

@@ -266,7 +268,7 @@ export default class WaDrawer extends WebAwesomeElement {
- ${this.withFooter + ${hasFooter ? html`