Skip to content

Commit

Permalink
(focus-trap/src/destination.ts) Fix inefficient code
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviDevMod committed May 19, 2023
1 parent 22641b7 commit 79b0e44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-moles-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@davidevmod/focus-trap': patch
---

Fix inefficient code in destination.ts
4 changes: 2 additions & 2 deletions packages/focus-trap/src/destination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ const nextFirstOrLastZeroOrPositiveTabbable = (
if (direction === 'BACKWARD') destinationRootIndex--;
}

const firstOrLastZeroInTrap = firstOrLastZeroTabbable(roots, direction === 'FORWARD' ? 'LAST' : 'FIRST');

for (let i = destinationRootIndex; Math.abs(i) < 2 * roots.length; i += direction === 'FORWARD' ? 1 : -1) {
const alternativeDestinationRootIndex = modulo(i, roots.length);

const firstOrLastZeroInTrap = firstOrLastZeroTabbable(roots, direction === 'FORWARD' ? 'LAST' : 'FIRST');

if (
!firstOrLastZeroInTrap ||
origin === firstOrLastZeroInTrap ||
Expand Down

0 comments on commit 79b0e44

Please sign in to comment.