@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
31 lines (30 loc) • 1.3 kB
JavaScript
/*!
* All material copyright ESRI, All Rights Reserved, unless otherwise specified.
* See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
* v1.5.0-next.4
*/
import { nodeListToArray } from "../../utils/dom";
import { ComboboxChildSelector } from "./resources";
import { Build } from "@stencil/core";
export function getAncestors(element) {
const parent = element.parentElement?.closest(ComboboxChildSelector);
const grandparent = parent?.parentElement?.closest(ComboboxChildSelector);
return [parent, grandparent].filter((el) => el);
}
export function getItemAncestors(item) {
return (item.ancestors?.filter((el) => el.nodeName === "CALCITE-COMBOBOX-ITEM") || []);
}
export function getItemChildren(item) {
return nodeListToArray(item.querySelectorAll("calcite-combobox-item"));
}
export function hasActiveChildren(node) {
const items = nodeListToArray(node.querySelectorAll("calcite-combobox-item"));
return items.filter((item) => item.selected).length > 0;
}
export function getDepth(element) {
if (!Build.isBrowser) {
return 0;
}
const result = document.evaluate("ancestor::calcite-combobox-item | ancestor::calcite-combobox-item-group", element, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
return result.snapshotLength;
}