Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public componentDidMount(): void {
_allInstances[this._id] = this
if (this._root.current) {
const windowElement = this._root.current.ownerDocument.defaultView
let parentElement = getParent(this._root.current, ALLOW_VIRTUAL_ELEMENTS)
while (parentElement && parentElement !== document.body && parentElement.nodeType === 1) {
if (isElementFocusZone(parentElement)) {
this._isInnerZone = true
break
}
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS)
}
if (!this._isInnerZone) {
this._events.on(windowElement, 'keydown', this.onKeyDownCapture, true)
}
// Assign initial tab indexes so that we can set initial focus as appropriate.
this.updateTabIndexes()
public componentDidMount(): void {
_allInstances[this._id] = this
if (this._root.current) {
const windowElement = this._root.current.ownerDocument.defaultView
let parentElement = getParent(this._root.current, ALLOW_VIRTUAL_ELEMENTS)
while (parentElement && parentElement !== document.body && parentElement.nodeType === 1) {
if (isElementFocusZone(parentElement)) {
this._isInnerZone = true
break
}
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS)
}
if (!this._isInnerZone) {
this._events.on(windowElement, 'keydown', this.onKeyDownCapture, true)
}
// Assign initial tab indexes so that we can set initial focus as appropriate.
this.updateTabIndexes()
if (this.props.defaultActiveElement) {
this._activeElement = getDocument()!.querySelector(
this.props.defaultActiveElement,
) as HTMLElement
this.focus()
}
}
private _onMouseDown = (ev: React.MouseEvent): void => {
const { disabled } = this.props
if (disabled) {
return
}
let target = ev.target as HTMLElement
const path = []
while (target && target !== this._root.current) {
path.push(target)
target = getParent(target, ALLOW_VIRTUAL_ELEMENTS) as HTMLElement
}
while (path.length) {
target = path.pop() as HTMLElement
if (target && isElementTabbable(target)) {
this.setActiveElement(target, true)
}
if (isElementFocusZone(target)) {
// Stop here since the focus zone will take care of its own children.
break
}
}
}
private getOwnerZone(element?: HTMLElement): HTMLElement | null {
let parentElement = getParent(element as HTMLElement, ALLOW_VIRTUAL_ELEMENTS)
while (
parentElement &&
parentElement !== this._root.current &&
parentElement !== document.body
) {
if (isElementFocusZone(parentElement)) {
return parentElement
}
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS)
}
return this._root.current
}
target.tagName === 'TEXTAREA'
) {
return false
}
if (
this.isImmediateDescendantOfZone(target) &&
target.getAttribute(IS_FOCUSABLE_ATTRIBUTE) === 'true' &&
target.getAttribute(IS_ENTER_DISABLED_ATTRIBUTE) !== 'true'
) {
EventGroup.raise(target, 'click', null, true)
return true
}
target = getParent(target, ALLOW_VIRTUAL_ELEMENTS) as HTMLElement
} while (target !== this._root.current)
return false
}
if (onFocusNotification) {
onFocusNotification()
}
if (this.isImmediateDescendantOfZone(ev.target as HTMLElement)) {
this._activeElement = ev.target as HTMLElement
this.setFocusAlignment(this._activeElement)
} else {
let parentElement = ev.target as HTMLElement
while (parentElement && parentElement !== this._root.current) {
if (isElementTabbable(parentElement) && this.isImmediateDescendantOfZone(parentElement)) {
this._activeElement = parentElement
break
}
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS) as HTMLElement
}
}
if (onActiveElementChanged) {
onActiveElementChanged(this._activeElement as HTMLElement, ev)
}
if (doNotAllowFocusEventToPropagate) {
ev.stopPropagation()
}
}
private getOwnerZone(element?: HTMLElement): HTMLElement | null {
let parentElement = getParent(element as HTMLElement, ALLOW_VIRTUAL_ELEMENTS)
while (
parentElement &&
parentElement !== this._root.current &&
parentElement !== document.body
) {
if (isElementFocusZone(parentElement)) {
return parentElement
}
parentElement = getParent(parentElement, ALLOW_VIRTUAL_ELEMENTS)
}
return this._root.current
}