Skip to content

Commit

Permalink
fix: remove visibility check from expandFocusableNodes
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Feb 14, 2024
1 parent b248f60 commit 543b9fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/focusables.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { getTabbableNodes } from './utils/DOMutils';
import { getAllAffectedNodes } from './utils/all-affected';
import { isGuard, isNotAGuard } from './utils/is';
import { getTopCommonParent } from './utils/parenting';
import { orderByTabIndex } from './utils/tabOrder';
import { getFocusables } from './utils/tabUtils';

interface FocusableNode {
node: HTMLElement;
Expand All @@ -28,11 +29,8 @@ interface FocusableNode {
export const expandFocusableNodes = (topNode: HTMLElement | HTMLElement[]): FocusableNode[] => {
const entries = getAllAffectedNodes(topNode).filter(isNotAGuard);
const commonParent = getTopCommonParent(topNode, topNode, entries);
const visibilityCache = new Map();
const outerNodes = getTabbableNodes([commonParent], visibilityCache, true);
const innerElements = getTabbableNodes(entries, visibilityCache)
.filter(({ node }) => isNotAGuard(node))
.map(({ node }) => node);
const outerNodes = orderByTabIndex(getFocusables([commonParent], true), true, true);
const innerElements = getFocusables(entries, false);

return outerNodes.map(
({ node, index }): FocusableNode => ({
Expand Down
3 changes: 3 additions & 0 deletions src/utils/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ const isTopNode = (node: Element): boolean =>

const isInert = (node: Element): boolean => node.hasAttribute('inert');

/**
* @see https://github.com/testing-library/jest-dom/blob/main/src/to-be-visible.js
*/
const isVisibleUncached = (node: Element | undefined, checkParent: CheckParentCallback): boolean =>
!node || isTopNode(node) || (!isElementHidden(node) && !isInert(node) && checkParent(getParentNode(node)));

Expand Down

0 comments on commit 543b9fe

Please sign in to comment.