Ignore excessive keydown events in charts (#24523)

* Ignore excessive keydown events in charts

* lint
This commit is contained in:
Petar Petrov 2025-03-06 12:30:17 +02:00 committed by GitHub
parent 75edc5132b
commit cdfe4b53bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

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