function beginFocusManagement()

in src/focus-zone.ts [415:437]


  function beginFocusManagement(...elements: HTMLElement[]) {
    const filteredElements = elements.filter(e => settings?.focusableElementFilter?.(e) ?? true)
    if (filteredElements.length === 0) {
      return
    }
    // Insert all elements atomically. Assume that all passed elements are well-ordered.
    const insertIndex = focusableElements.findIndex(
      e => (e.compareDocumentPosition(filteredElements[0]) & Node.DOCUMENT_POSITION_PRECEDING) > 0
    )
    focusableElements.splice(insertIndex === -1 ? focusableElements.length : insertIndex, 0, ...filteredElements)
    for (const element of filteredElements) {
      // Set tabindex="-1" on all tabbable elements, but save the original
      // value in case we need to disable the behavior
      if (!savedTabIndex.has(element)) {
        savedTabIndex.set(element, element.getAttribute('tabindex'))
      }
      element.setAttribute('tabindex', '-1')
    }

    if (!currentFocusedElement) {
      updateFocusedElement(getFirstFocusableElement())
    }
  }