Skip to content

Commit

Permalink
refactor: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Dec 11, 2024
1 parent 1a67713 commit 48a954b
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/virtual-list/src/vaadin-virtual-list-selection-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { getFocusableElements } from '@vaadin/a11y-base';
import { timeOut } from '@vaadin/component-base/src/async';
import { timeOut } from '@vaadin/component-base/src/async.js';
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
import { get } from '@vaadin/component-base/src/path-utils.js';

Expand Down Expand Up @@ -147,8 +147,8 @@ export const SelectionMixin = (superClass) =>
}

/** @private */
__clampIndex(index) {
return Math.max(0, Math.min(index, (this.items || []).length - 1));
__updateFocusIndex(index) {
this.__focusIndex = Math.max(0, Math.min(index, (this.items || []).length - 1));
}

/** @private */
Expand All @@ -158,9 +158,9 @@ export const SelectionMixin = (superClass) =>
}

const oldFocusIndex = this.__focusIndex;
this.__focusIndex = this.__clampIndex(this.__focusIndex);
this.__updateFocusIndex(this.__focusIndex);
if (oldFocusIndex !== this.__focusIndex) {
this.__scheduleRequestContentUpdate();
this.__scheduleContentUpdate();
}
// Items may have been emptied, need to update focusability
this.__updateFocusable();
Expand All @@ -173,7 +173,7 @@ export const SelectionMixin = (superClass) =>

/** @private */
__selectionChanged() {
this.__scheduleRequestContentUpdate();
this.__scheduleContentUpdate();
}

/** @private */
Expand Down Expand Up @@ -254,7 +254,7 @@ export const SelectionMixin = (superClass) =>
}

/**
* Returns the rendered root element containing the given child element.
* Returns the rendered root element matching or containing the given child element.
* @private
*/
__getRootElementByContent(element) {
Expand All @@ -275,7 +275,7 @@ export const SelectionMixin = (superClass) =>
this.toggleAttribute('interacting', isInteracting);

this.__updateFocusable();
this.__scheduleRequestContentUpdate();
this.__scheduleContentUpdate();
}

/** @private */
Expand Down Expand Up @@ -322,7 +322,7 @@ export const SelectionMixin = (superClass) =>

/** @private */
__onNavigationArrowKey(down) {
this.__focusIndex = this.__clampIndex(this.__focusIndex + (down ? 1 : -1));
this.__updateFocusIndex(this.__focusIndex + (down ? 1 : -1));
this.__focusElementWithFocusIndex();

if (this.__debounceRequestContentUpdate) {
Expand All @@ -332,7 +332,7 @@ export const SelectionMixin = (superClass) =>
}

/** @private */
__scheduleRequestContentUpdate() {
__scheduleContentUpdate() {
this.__debounceRequestContentUpdate = Debouncer.debounce(
this.__debounceRequestContentUpdate,
timeOut.after(0),
Expand Down Expand Up @@ -370,7 +370,7 @@ export const SelectionMixin = (superClass) =>
__onNavigationEnterKey() {
// Get the focused item
const focusedItem = this.querySelector('[focused]');
// First the first focusable element in the focused item and focus it
// Find the first focusable element in the item and focus it
const focusableElement = getFocusableElements(focusedItem).find((el) => el !== focusedItem);
if (focusableElement) {
focusableElement.focus();
Expand Down Expand Up @@ -409,7 +409,7 @@ export const SelectionMixin = (superClass) =>
// Update focus index based on the focused item
const rootElement = this.__getRootElementWithFocus();
if (rootElement) {
this.__focusIndex = rootElement.__index;
this.__updateFocusIndex(rootElement.__index);
}

// Focus the root element matching focus index if focus came from outside
Expand Down

0 comments on commit 48a954b

Please sign in to comment.