From e45e4cd3d59c75f3433d2b44b5da2a7806a64e6f Mon Sep 17 00:00:00 2001 From: Sergey Vinogradov Date: Wed, 16 Oct 2024 09:00:33 +0400 Subject: [PATCH] refactor: convert class property to local variable (#7975) --- packages/grid/src/vaadin-grid-scroll-mixin.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/grid/src/vaadin-grid-scroll-mixin.js b/packages/grid/src/vaadin-grid-scroll-mixin.js index 5725f6305e..0573fb2400 100644 --- a/packages/grid/src/vaadin-grid-scroll-mixin.js +++ b/packages/grid/src/vaadin-grid-scroll-mixin.js @@ -81,9 +81,6 @@ export const ScrollMixin = (superClass) => type: Array, value: () => [], }, - - /** @private */ - _rowWithFocusedElement: Element, }; } @@ -121,28 +118,23 @@ export const ScrollMixin = (superClass) => this.scrollTarget = this.$.table; this.$.items.addEventListener('focusin', (e) => { - const itemsIndex = e.composedPath().indexOf(this.$.items); - this._rowWithFocusedElement = e.composedPath()[itemsIndex - 1]; + const composedPath = e.composedPath(); + const row = composedPath[composedPath.indexOf(this.$.items) - 1]; - if (this._rowWithFocusedElement) { + if (row) { // Make sure the row with the focused element is fully inside the visible viewport // Don't change scroll position if the user is interacting with the mouse if (!this._isMousedown) { - this.__scrollIntoViewport(this._rowWithFocusedElement.index); + this.__scrollIntoViewport(row.index); } if (!this.$.table.contains(e.relatedTarget)) { // Virtualizer can't catch the event because if orginates from the light DOM. // Dispatch a virtualizer-element-focused event for virtualizer to catch. - this.$.table.dispatchEvent( - new CustomEvent('virtualizer-element-focused', { detail: { element: this._rowWithFocusedElement } }), - ); + this.$.table.dispatchEvent(new CustomEvent('virtualizer-element-focused', { detail: { element: row } })); } } }); - this.$.items.addEventListener('focusout', () => { - this._rowWithFocusedElement = undefined; - }); this.$.table.addEventListener('scroll', () => this._afterScroll()); }