mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
Perform action in slider and switch if it's a long press (#24579)
This commit is contained in:
parent
1b6d2ac08e
commit
e8805be561
@ -1,4 +1,4 @@
|
||||
import { DIRECTION_ALL, Manager, Pan, Tap } from "@egjs/hammerjs";
|
||||
import { DIRECTION_ALL, Manager, Pan, Press, Tap } from "@egjs/hammerjs";
|
||||
import type { PropertyValues, TemplateResult } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
@ -159,6 +159,7 @@ export class HaControlSlider extends LitElement {
|
||||
);
|
||||
|
||||
this._mc.add(new Tap({ event: "singletap" }));
|
||||
this._mc.add(new Press());
|
||||
|
||||
let savedValue;
|
||||
this._mc.on("panstart", () => {
|
||||
@ -190,7 +191,7 @@ export class HaControlSlider extends LitElement {
|
||||
fireEvent(this, "value-changed", { value: this.value });
|
||||
});
|
||||
|
||||
this._mc.on("singletap", (e) => {
|
||||
this._mc.on("singletap pressup", (e) => {
|
||||
if (this.disabled) return;
|
||||
const percentage = this._getPercentageFromEvent(e);
|
||||
this.value = this.steppedValue(this.percentageToValue(percentage));
|
||||
|
@ -2,6 +2,7 @@ import {
|
||||
DIRECTION_HORIZONTAL,
|
||||
DIRECTION_VERTICAL,
|
||||
Manager,
|
||||
Press,
|
||||
Swipe,
|
||||
Tap,
|
||||
} from "@egjs/hammerjs";
|
||||
@ -79,6 +80,7 @@ export class HaControlSwitch extends LitElement {
|
||||
);
|
||||
|
||||
this._mc.add(new Tap({ event: "singletap" }));
|
||||
this._mc.add(new Press());
|
||||
|
||||
if (this.vertical) {
|
||||
this._mc.on("swipeup", () => {
|
||||
@ -106,10 +108,11 @@ export class HaControlSwitch extends LitElement {
|
||||
});
|
||||
}
|
||||
|
||||
this._mc.on("singletap", () => {
|
||||
this._mc.on("singletap pressup", () => {
|
||||
if (this.disabled) return;
|
||||
this._toggle();
|
||||
});
|
||||
|
||||
this.addEventListener("keydown", this._keydown);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user