Skip to content

Commit

Permalink
refactor: convert class property to local variable (#7975)
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen authored Oct 16, 2024
1 parent b3e1a4f commit e45e4cd
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions packages/grid/src/vaadin-grid-scroll-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ export const ScrollMixin = (superClass) =>
type: Array,
value: () => [],
},

/** @private */
_rowWithFocusedElement: Element,
};
}

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

0 comments on commit e45e4cd

Please sign in to comment.