@ariakit/react-core
Version:
Ariakit React core
98 lines (96 loc) • 2.48 kB
JavaScript
"use client";
import {
useCompositeItemOffscreen
} from "../__chunks/BHWLTE4Z.js";
import {
ComboboxItem
} from "../__chunks/T2NLLS6H.js";
import "../__chunks/HBZ7G2WX.js";
import "../__chunks/JT5CKSP7.js";
import "../__chunks/7NJRHOSP.js";
import "../__chunks/GIQLGI43.js";
import {
Role
} from "../__chunks/AB647VKY.js";
import "../__chunks/4WQSNMEM.js";
import {
ComboboxListRoleContext,
useComboboxScopedContext
} from "../__chunks/6C2ASARV.js";
import "../__chunks/467XRHWL.js";
import "../__chunks/2LVHRIRC.js";
import "../__chunks/FYYAZUDI.js";
import "../__chunks/NO3UEYQ2.js";
import "../__chunks/EZ4UPVW6.js";
import "../__chunks/3F6D4KUU.js";
import "../__chunks/SWN3JYXT.js";
import "../__chunks/SOQQIDO4.js";
import "../__chunks/CTVD4XJH.js";
import {
forwardRef
} from "../__chunks/L4OUMOCQ.js";
import {
useMergeRefs
} from "../__chunks/W2TDKEPX.js";
import "../__chunks/AZVQSWGA.js";
// src/combobox/combobox-item-offscreen.tsx
import { useContext } from "react";
import { jsx } from "react/jsx-runtime";
var TagName = "div";
var itemRoleByPopupRole = {
menu: "menuitem",
listbox: "option",
tree: "treeitem"
};
function getItemRole(popupRole) {
var _a;
const key = popupRole;
return (_a = itemRoleByPopupRole[key]) != null ? _a : "option";
}
function useComboboxItemOffscreen({ store, value, ...props }) {
const context = useComboboxScopedContext();
store = store || context;
const offscreenProps = useCompositeItemOffscreen({ store, value, ...props });
const popupRole = useContext(ComboboxListRoleContext);
if (!offscreenProps.active) {
return {
...offscreenProps,
role: getItemRole(popupRole)
};
}
return offscreenProps;
}
var ComboboxItem2 = forwardRef(function ComboboxItem3({
offscreenMode,
offscreenRoot,
...props
}) {
const { active, ref, ...rest } = useComboboxItemOffscreen({
offscreenMode,
offscreenRoot,
...props
});
const allProps = { ...rest, ...props, ref: useMergeRefs(ref, props.ref) };
if (active) {
return /* @__PURE__ */ jsx(ComboboxItem, { ...allProps });
}
const {
store,
value,
hideOnClick,
setValueOnClick,
selectValueOnClick,
resetValueOnSelect,
focusOnHover,
blurOnHoverEnd,
moveOnKeyPress,
getItem,
...htmlProps
} = allProps;
const Component = Role[TagName];
return /* @__PURE__ */ jsx(Component, { ...htmlProps });
});
export {
ComboboxItem2 as ComboboxItem,
useComboboxItemOffscreen
};