Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
} while (element)
// Focus the closest candidate
if (candidateElement && candidateElement !== this._activeElement) {
changedFocus = true
this.focusElement(candidateElement)
} else if (this.props.isCircularNavigation && useDefaultWrap) {
if (isForward) {
return this.focusElement(getNextElement(
this._root.current,
this._root.current.firstElementChild as HTMLElement,
true,
) as HTMLElement)
}
return this.focusElement(getPreviousElement(
this._root.current,
this._root.current.lastElementChild as HTMLElement,
true,
true,
true,
) as HTMLElement)
}
return changedFocus
}
if (!element || !this._root.current) {
return false
}
if (this.isElementInput(element)) {
if (!this.shouldInputLoseFocus(element as HTMLInputElement, isForward)) {
return false
}
}
const activeRect = isBidirectional ? element.getBoundingClientRect() : null
do {
element = (isForward
? getNextElement(this._root.current, element)
: getPreviousElement(this._root.current, element)) as HTMLElement
if (isBidirectional) {
if (element) {
const targetRect = element.getBoundingClientRect()
const elementDistance = getDistanceFromCenter(activeRect as ClientRect, targetRect)
if (elementDistance === -1 && candidateDistance === -1) {
candidateElement = element
break
}
if (
elementDistance > -1 &&
(candidateDistance === -1 || elementDistance < candidateDistance)
) {
candidateDistance = elementDistance
}
return
case KeyCodes.end:
if (
this.isElementInput(ev.target as HTMLElement) &&
!this.shouldInputLoseFocus(ev.target as HTMLInputElement, true)
) {
return false
}
const lastChild =
this._root.current && (this._root.current.lastChild as HTMLElement | null)
if (
this._root.current &&
this.focusElement(getPreviousElement(
this._root.current,
lastChild,
true,
true,
true,
) as HTMLElement)
) {
break
}
return
case KeyCodes.enter:
if (this.tryInvokeClickForFocusable(ev.target as HTMLElement)) {
break
}
return