function targetWithinDownshift(
  target,
  downshiftElements,
  environment,
  checkActiveElement = true,
) {
  return (
    environment &&
    downshiftElements.some(
      contextNode =>
        contextNode &&
        (isOrContainsNode(contextNode, target, environment) ||
          (checkActiveElement &&
            isOrContainsNode(
              contextNode,
              environment.document.activeElement,
              environment,
            ))),
    )
  )
}
Checks if event target is within the downshift elements.

@param {EventTarget} target Target to check.
@param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
@param {Window} environment The window context where downshift renders.
@param {boolean} checkActiveElement Whether to also check activeElement.

@returns {boolean} Whether or not the target is within downshift elements.