Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert class property to local variable #7975

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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