Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vursen committed Jan 16, 2025
1 parent e989a7c commit 141c7c5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
9 changes: 0 additions & 9 deletions packages/a11y-base/src/focus-utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ export declare function getDeepActiveElement(): Element;
*/
export declare function isKeyboardActive(): boolean;

/**
* Returns true if the element is hidden directly with `display: none` or `visibility: hidden`,
* false otherwise.
*
* The method doesn't traverse the element's ancestors, it only checks for the CSS properties
* set directly to or inherited by the element.
*/
export declare function isElementHiddenDirectly(element: HTMLElement): boolean;

/**
* Returns true if the element is hidden, false otherwise.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/a11y-base/src/focus-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function isKeyboardActive() {
* @param {HTMLElement} element
* @return {boolean}
*/
export function isElementHiddenDirectly(element) {
function isElementHiddenDirectly(element) {
// Check inline style first to save a re-flow.
const style = element.style;
if (style.visibility === 'hidden' || style.display === 'none') {
Expand Down
13 changes: 9 additions & 4 deletions packages/a11y-base/src/list-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Debouncer } from '@vaadin/component-base/src/debounce.js';
import { getNormalizedScrollLeft, setNormalizedScrollLeft } from '@vaadin/component-base/src/dir-utils.js';
import { getFlattenedElements } from '@vaadin/component-base/src/dom-utils.js';
import { SlotObserver } from '@vaadin/component-base/src/slot-observer.js';
import { isElementHiddenDirectly } from './focus-utils.js';
import { isElementHidden } from './focus-utils.js';
import { KeyboardDirectionMixin } from './keyboard-direction-mixin.js';

/**
Expand Down Expand Up @@ -120,7 +120,7 @@ export const ListMixin = (superClass) =>
}

const items = Array.isArray(this.items) ? this.items : [];
const idx = this._getAvailableIndex(items, 0, null, (item) => item.tabIndex === 0);
const idx = this._getAvailableIndex(items, 0, null, (item) => item.tabIndex === 0 && !isElementHidden(item));
if (idx >= 0) {
this._focus(idx);
} else {
Expand Down Expand Up @@ -222,7 +222,12 @@ export const ListMixin = (superClass) =>
}

const idx = this._searchBuf.length === 1 ? currentIdx + 1 : currentIdx;
return this._getAvailableIndex(this.items, idx, 1, (item) => this.__isMatchingKey(item));
return this._getAvailableIndex(
this.items,
idx,
1,
(item) => this.__isMatchingKey(item) && getComputedStyle(item).display !== 'none',
);
}

/** @private */
Expand Down Expand Up @@ -334,7 +339,7 @@ export const ListMixin = (superClass) =>

/** @override */
_isItemFocusable(item) {
return !item.hasAttribute('disabled') && !isElementHiddenDirectly(item);
return !item.hasAttribute('disabled');
}

/**
Expand Down

0 comments on commit 141c7c5

Please sign in to comment.