Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setTimeout(() => {
// timeout so we can check where focus went to
if (!containsActiveElement(this._menu)) {
// is focus still not on an option
this.close(event)
}
}, 0)
)
function scopeTab (element, event, onLeavingFinalTabbable) {
const node = findDOMNode(element)
const tabbable = findTabbable(node)
if (!tabbable.length) {
event.preventDefault()
return
}
// Account for a changing tabindex of the active element
// (a case that happens with Menu for KO a11y)
if (containsActiveElement(element)) {
const activeElement = getActiveElement()
if (tabbable.indexOf(activeElement) === -1) {
tabbable.push(activeElement)
}
}
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1]
const leavingFinalTabbable = (
isActiveElement(finalTabbable) ||
// handle immediate shift+tab after opening with mouse
isActiveElement(node) ||
// already left final tabbable
!containsActiveElement(element)
)
if (!leavingFinalTabbable) return
// Account for a changing tabindex of the active element
// (a case that happens with Menu for KO a11y)
if (containsActiveElement(element)) {
const activeElement = getActiveElement()
if (tabbable.indexOf(activeElement) === -1) {
tabbable.push(activeElement)
}
}
const finalTabbable = tabbable[event.shiftKey ? 0 : tabbable.length - 1]
const leavingFinalTabbable = (
isActiveElement(finalTabbable) ||
// handle immediate shift+tab after opening with mouse
isActiveElement(node) ||
// already left final tabbable
!containsActiveElement(element)
)
if (!leavingFinalTabbable) return
if (typeof onLeavingFinalTabbable === 'function') {
onLeavingFinalTabbable()
return
}
event.preventDefault()
const target = tabbable[event.shiftKey ? tabbable.length - 1 : 0]
target.focus()
}
get focused () {
return containsActiveElement(this)
}
get focused () {
return containsActiveElement(this._contextElement)
}
get focused () {
return containsActiveElement(this._contentElement)
}
focused () {
if (this.shown) {
return containsActiveElement(this._menu) || this.state.hasFocus
} else {
return containsActiveElement(this._trigger)
}
}
focused () {
if (this.shown) {
return containsActiveElement(this._menu) || this.state.hasFocus
} else {
return containsActiveElement(this._trigger)
}
}
requestAnimationFrame(() => {
if (containsActiveElement(this._contextElement)) {
return
}
this.focusDefaultElement()
})
)
this._raf.push(requestAnimationFrame(() => {
if (!containsActiveElement(this._view)) {
this.hide(event)
}
}))
}