From cdfe4b53bf18d974f8a305d7e7954403316857f8 Mon Sep 17 00:00:00 2001 From: Petar Petrov Date: Thu, 6 Mar 2025 12:30:17 +0200 Subject: [PATCH] Ignore excessive keydown events in charts (#24523) * Ignore excessive keydown events in charts * lint --- src/components/chart/ha-chart-base.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/components/chart/ha-chart-base.ts b/src/components/chart/ha-chart-base.ts index 8bda2bfba8..bbf2fcacd7 100644 --- a/src/components/chart/ha-chart-base.ts +++ b/src/components/chart/ha-chart-base.ts @@ -108,7 +108,10 @@ export class HaChartBase extends LitElement { // Add keyboard event listeners const handleKeyDown = (ev: KeyboardEvent) => { - if ((isMac && ev.key === "Meta") || (!isMac && ev.key === "Control")) { + if ( + !this._modifierPressed && + ((isMac && ev.key === "Meta") || (!isMac && ev.key === "Control")) + ) { this._modifierPressed = true; if (!this.options?.dataZoom) { this._setChartOptions({ dataZoom: this._getDataZoomConfig() }); @@ -123,7 +126,10 @@ export class HaChartBase extends LitElement { }; const handleKeyUp = (ev: KeyboardEvent) => { - if ((isMac && ev.key === "Meta") || (!isMac && ev.key === "Control")) { + if ( + this._modifierPressed && + ((isMac && ev.key === "Meta") || (!isMac && ev.key === "Control")) + ) { this._modifierPressed = false; if (!this.options?.dataZoom) { this._setChartOptions({ dataZoom: this._getDataZoomConfig() });