MCPcopy Create free account
hub / github.com/testing-library/user-event / getNextElement

Function getNextElement

src/tab.ts:12–29  ·  view source on GitHub ↗
(
  currentIndex: number,
  shift: boolean,
  elements: Element[],
  focusTrap: Document | Element,
)

Source from the content-addressed store, hash-verified

10import {blur} from './blur'
11
12function getNextElement(
13 currentIndex: number,
14 shift: boolean,
15 elements: Element[],
16 focusTrap: Document | Element,
17) {
18 if (
19 isDocument(focusTrap) &&
20 ((currentIndex === 0 && shift) ||
21 (currentIndex === elements.length - 1 && !shift))
22 ) {
23 return focusTrap.body
24 }
25
26 const nextIndex = shift ? currentIndex - 1 : currentIndex + 1
27 const defaultIndex = shift ? elements.length - 1 : 0
28 return elements[nextIndex] || elements[defaultIndex]
29}
30
31interface tabOptions {
32 shift?: boolean

Callers 1

tabFunction · 0.85

Calls 1

isDocumentFunction · 0.90

Tested by

no test coverage detected