How to use the @uifabric/utilities.getParent function in @uifabric/utilities

To help you get started, we’ve selected a few @uifabric/utilities examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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()
github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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()
      }
    }
github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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
      }
    }
  }
github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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
  }
github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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
  }
github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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()
    }
  }
github microsoft / fluent-ui-react / src / components / FocusZone / FocusZone.tsx View on Github external
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
  }