mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Add swipe to close action to drawer in modal mode (#16042)
This commit is contained in:
parent
fdf36adc3c
commit
36b2a1bca3
@ -1,12 +1,16 @@
|
|||||||
|
import { DIRECTION_LEFT, Manager, Swipe } from "@egjs/hammerjs";
|
||||||
import { DrawerBase } from "@material/mwc-drawer/mwc-drawer-base";
|
import { DrawerBase } from "@material/mwc-drawer/mwc-drawer-base";
|
||||||
import { styles } from "@material/mwc-drawer/mwc-drawer.css";
|
import { styles } from "@material/mwc-drawer/mwc-drawer.css";
|
||||||
import { css } from "lit";
|
import { css, PropertyValues } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
|
||||||
const blockingElements = (document as any).$blockingElements;
|
const blockingElements = (document as any).$blockingElements;
|
||||||
|
|
||||||
@customElement("ha-drawer")
|
@customElement("ha-drawer")
|
||||||
export class HaDrawer extends DrawerBase {
|
export class HaDrawer extends DrawerBase {
|
||||||
|
private _mc?: HammerManager;
|
||||||
|
|
||||||
protected createAdapter() {
|
protected createAdapter() {
|
||||||
return {
|
return {
|
||||||
...super.createAdapter(),
|
...super.createAdapter(),
|
||||||
@ -23,6 +27,26 @@ export class HaDrawer extends DrawerBase {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected updated(changedProps: PropertyValues) {
|
||||||
|
super.updated(changedProps);
|
||||||
|
if (changedProps.has("open") && this.open && this.type === "modal") {
|
||||||
|
this._mc = new Manager(document, {
|
||||||
|
touchAction: "pan-y",
|
||||||
|
});
|
||||||
|
this._mc.add(
|
||||||
|
new Swipe({
|
||||||
|
direction: DIRECTION_LEFT,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this._mc.on("swipeleft", () => {
|
||||||
|
fireEvent(this, "hass-toggle-menu", { open: false });
|
||||||
|
});
|
||||||
|
} else if (this._mc) {
|
||||||
|
this._mc.destroy();
|
||||||
|
this._mc = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static override styles = [
|
static override styles = [
|
||||||
styles,
|
styles,
|
||||||
css`
|
css`
|
||||||
|
@ -28,8 +28,8 @@ import {
|
|||||||
CSSResultGroup,
|
CSSResultGroup,
|
||||||
html,
|
html,
|
||||||
LitElement,
|
LitElement,
|
||||||
PropertyValues,
|
|
||||||
nothing,
|
nothing,
|
||||||
|
PropertyValues,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, eventOptions, property, state } from "lit/decorators";
|
import { customElement, eventOptions, property, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user