Skip to content

Commit e388756

Browse files
authored
ha-wa-dialog show header border on scroll (#27605)
1 parent e9ca9bb commit e388756

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/components/ha-dialog-header.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ export class HaDialogHeader extends LitElement {
66
@property({ type: String, attribute: "subtitle-position" })
77
public subtitlePosition: "above" | "below" = "below";
88

9+
@property({ type: Boolean, reflect: true, attribute: "show-border" })
10+
public showBorder = false;
11+
912
protected render() {
1013
const titleSlot = html`<div class="header-title">
1114
<slot name="title"></slot>

src/components/ha-wa-dialog.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { css, html, LitElement, nothing } from "lit";
2-
import { customElement, property, state } from "lit/decorators";
31
import "@home-assistant/webawesome/dist/components/dialog/dialog";
42
import { mdiClose } from "@mdi/js";
5-
import "./ha-dialog-header";
6-
import "./ha-icon-button";
7-
import type { HomeAssistant } from "../types";
3+
import { css, html, LitElement, nothing } from "lit";
4+
import { customElement, eventOptions, property, state } from "lit/decorators";
85
import { fireEvent } from "../common/dom/fire_event";
96
import { haStyleScrollbar } from "../resources/styles";
7+
import type { HomeAssistant } from "../types";
8+
import "./ha-dialog-header";
9+
import "./ha-icon-button";
1010

1111
export type DialogWidth = "small" | "medium" | "large" | "full";
1212

@@ -90,6 +90,9 @@ export class HaWaDialog extends LitElement {
9090
@state()
9191
private _open = false;
9292

93+
@state()
94+
private _bodyScrolled = false;
95+
9396
protected updated(
9497
changedProperties: Map<string | number | symbol, unknown>
9598
): void {
@@ -110,7 +113,10 @@ export class HaWaDialog extends LitElement {
110113
@wa-after-hide=${this._handleAfterHide}
111114
>
112115
<slot name="header">
113-
<ha-dialog-header .subtitlePosition=${this.headerSubtitlePosition}>
116+
<ha-dialog-header
117+
.subtitlePosition=${this.headerSubtitlePosition}
118+
.showBorder=${this._bodyScrolled}
119+
>
114120
<slot name="headerNavigationIcon" slot="navigationIcon">
115121
<ha-icon-button
116122
data-dialog="close"
@@ -129,7 +135,7 @@ export class HaWaDialog extends LitElement {
129135
<slot name="headerActionItems" slot="actionItems"></slot>
130136
</ha-dialog-header>
131137
</slot>
132-
<div class="body ha-scrollbar">
138+
<div class="body ha-scrollbar" @scroll=${this._handleBodyScroll}>
133139
<slot></slot>
134140
</div>
135141
<slot name="footer" slot="footer"></slot>
@@ -156,6 +162,11 @@ export class HaWaDialog extends LitElement {
156162
this._open = false;
157163
}
158164

165+
@eventOptions({ passive: true })
166+
private _handleBodyScroll(ev: Event) {
167+
this._bodyScrolled = (ev.target as HTMLDivElement).scrollTop > 0;
168+
}
169+
159170
static styles = [
160171
haStyleScrollbar,
161172
css`

0 commit comments

Comments
 (0)