Function
getNextElement
(
currentIndex: number,
shift: boolean,
elements: Element[],
focusTrap: Document | Element,
)
Source from the content-addressed store, hash-verified
| 10 | import {blur} from './blur' |
| 11 | |
| 12 | function 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 | |
| 31 | interface tabOptions { |
| 32 | shift?: boolean |
Tested by
no test coverage detected