Perform action in slider and switch if it's a long press (#24579)

This commit is contained in:
Paul Bottein 2025-03-10 15:30:29 +01:00 committed by GitHub
parent 1b6d2ac08e
commit e8805be561
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 3 deletions

View File

@ -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));

View File

@ -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);
}
}