diff --git a/src/components/ha-bottom-sheet.ts b/src/components/ha-bottom-sheet.ts index 5737fe9750..49914f6e7d 100644 --- a/src/components/ha-bottom-sheet.ts +++ b/src/components/ha-bottom-sheet.ts @@ -30,6 +30,8 @@ export class HaBottomSheet extends LitElement { @state() private _dialogMaxViewpointHeight = 70; + @state() private _dialogMinViewpointHeight = 55; + @state() private _dialogViewportHeight?: number; render() { @@ -41,6 +43,7 @@ export class HaBottomSheet extends LitElement { ? `${this._dialogViewportHeight}vh` : "auto", maxHeight: `${this._dialogMaxViewpointHeight}vh`, + minHeight: `${this._dialogMinViewpointHeight}vh`, })} >
@@ -80,6 +83,7 @@ export class HaBottomSheet extends LitElement { this._dialogViewportHeight = (this._dialog.offsetHeight / window.innerHeight) * 100; this._dialogMaxViewpointHeight = 90; + this._dialogMinViewpointHeight = 20; } else { // after close animation is done close dialog element and fire closed event this._dialog.close(); diff --git a/src/panels/config/automation/sidebar/ha-automation-sidebar-card.ts b/src/panels/config/automation/sidebar/ha-automation-sidebar-card.ts index bac43f2660..a7920ccd43 100644 --- a/src/panels/config/automation/sidebar/ha-automation-sidebar-card.ts +++ b/src/panels/config/automation/sidebar/ha-automation-sidebar-card.ts @@ -1,4 +1,6 @@ +import { ResizeController } from "@lit-labs/observers/resize-controller"; import { mdiClose, mdiDotsVertical } from "@mdi/js"; +import type { PropertyValues } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { customElement, @@ -43,7 +45,22 @@ export default class HaAutomationSidebarCard extends LitElement { @state() private _contentScrolled = false; - @query(".card-content") private _contentElement?: HTMLDivElement; + @state() private _contentScrollable = false; + + @query(".card-content") private _contentElement!: HTMLDivElement; + + private _contentSize = new ResizeController(this, { + target: null, + callback: (entries) => { + if (entries[0]?.target) { + this._canScrollDown(entries[0].target); + } + }, + }); + + protected firstUpdated(_changedProperties: PropertyValues): void { + this._contentSize.observe(this._contentElement); + } protected render() { return html` @@ -94,14 +111,29 @@ export default class HaAutomationSidebarCard extends LitElement {
+ ${this.narrow + ? html` +
+ ` + : nothing} `; } @eventOptions({ passive: true }) - private _onScroll() { - const top = this._contentElement?.scrollTop ?? 0; + private _onScroll(ev) { + const top = ev.target.scrollTop ?? 0; this._contentScrolled = top > 0; + + this._canScrollDown(ev.target); + } + + private _canScrollDown(element: HTMLElement) { + this._contentScrollable = + (element.scrollHeight ?? 0) - (element.clientHeight ?? 0) > + (element.scrollTop ?? 0); } private _closeSidebar() { @@ -151,6 +183,20 @@ export default class HaAutomationSidebarCard extends LitElement { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12); } + .fade { + position: fixed; + bottom: -12px; + left: 0; + right: 0; + height: 12px; + pointer-events: none; + transition: box-shadow 180ms ease-in-out; + } + + .fade.scrollable { + box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.16); + } + .card-content { max-height: calc(100% - 80px); overflow: auto;