UNPKG

@ariakit/react-core

Version:

Ariakit React core

170 lines (152 loc) 6.52 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _XPWK4QRCcjs = require('../__chunks/XPWK4QRC.cjs'); var _6SC6IEJJcjs = require('../__chunks/6SC6IEJJ.cjs'); require('../__chunks/6NFJUQ7Q.cjs'); require('../__chunks/UI5KWBYV.cjs'); require('../__chunks/L634CRNJ.cjs'); require('../__chunks/3PV6Y4XH.cjs'); require('../__chunks/WWNMQZJA.cjs'); require('../__chunks/CXFFS6H4.cjs'); require('../__chunks/W32FX7DM.cjs'); require('../__chunks/ERSQB5XO.cjs'); require('../__chunks/5RIUFRY2.cjs'); require('../__chunks/HMJY2Y4H.cjs'); require('../__chunks/JQCSYNKY.cjs'); require('../__chunks/MXT5U5PP.cjs'); require('../__chunks/JLMLKTUB.cjs'); require('../__chunks/LCWSLOYU.cjs'); require('../__chunks/V7JASX7S.cjs'); require('../__chunks/56NPFF7P.cjs'); require('../__chunks/GASMO7Y4.cjs'); require('../__chunks/O5T5YIJ4.cjs'); require('../__chunks/26P4PLHI.cjs'); require('../__chunks/YVOQ2BCB.cjs'); require('../__chunks/4SKDRUBR.cjs'); require('../__chunks/AQ2LO7WV.cjs'); var _YCTFY2SBcjs = require('../__chunks/YCTFY2SB.cjs'); require('../__chunks/DRXSFB5O.cjs'); require('../__chunks/EM3Q5QVV.cjs'); require('../__chunks/XRHNSFIK.cjs'); require('../__chunks/4IRVZ6J3.cjs'); var _IOFHSY3Lcjs = require('../__chunks/IOFHSY3L.cjs'); require('../__chunks/7X7JMIHX.cjs'); require('../__chunks/WDV6EJ2U.cjs'); require('../__chunks/VFNUZFXS.cjs'); require('../__chunks/EOGOO37X.cjs'); require('../__chunks/BB34VMZX.cjs'); require('../__chunks/T3QB4FR3.cjs'); var _RDNUVX4Vcjs = require('../__chunks/RDNUVX4V.cjs'); require('../__chunks/ZYZTL3IQ.cjs'); var _SQLDFLTEcjs = require('../__chunks/SQLDFLTE.cjs'); require('../__chunks/4KGS3DOW.cjs'); require('../__chunks/TWX5YNTH.cjs'); // src/combobox/combobox-popover.tsx var _dom = require('@ariakit/core/utils/dom'); var _misc = require('@ariakit/core/utils/misc'); var _react = require('react'); var TagName = "div"; function isController(target, ...ids) { if (!target) return false; if ("id" in target) { const selector = ids.filter(Boolean).map((id) => `[aria-controls~="${id}"]`).join(", "); if (!selector) return false; return target.matches(selector); } return false; } var useComboboxPopover = _SQLDFLTEcjs.createHook.call(void 0, function useComboboxPopover2({ store, modal, tabIndex, alwaysVisible, autoFocusOnHide = true, hideOnInteractOutside = true, ...props }) { const context = _IOFHSY3Lcjs.useComboboxProviderContext.call(void 0, ); store = store || context; _misc.invariant.call(void 0, store, process.env.NODE_ENV !== "production" && "ComboboxPopover must receive a `store` prop or be wrapped in a ComboboxProvider component." ); const baseElement = _RDNUVX4Vcjs.useStoreState.call(void 0, store, "baseElement"); const hiddenByClickOutsideRef = _react.useRef.call(void 0, false); const treeSnapshotKey = _RDNUVX4Vcjs.useStoreState.call(void 0, store.tag, (state) => state == null ? void 0 : state.renderedItems.length ); props = _YCTFY2SBcjs.useComboboxList.call(void 0, { store, alwaysVisible, ...props }); props = _XPWK4QRCcjs.usePopover.call(void 0, { store, modal, alwaysVisible, backdrop: false, autoFocusOnShow: false, finalFocus: baseElement, preserveTabOrderAnchor: null, unstable_treeSnapshotKey: treeSnapshotKey, ...props, // When the combobox popover is modal, we make sure to include the // combobox input and all the combobox controls (cancel, disclosure) in // the list of persistent elements so they make part of the modal context, // allowing users to tab through them. getPersistentElements() { var _a; const elements = ((_a = props.getPersistentElements) == null ? void 0 : _a.call(props)) || []; if (!modal) return elements; if (!store) return elements; const { contentElement, baseElement: baseElement2 } = store.getState(); if (!baseElement2) return elements; const doc = _dom.getDocument.call(void 0, baseElement2); const selectors = []; if (contentElement == null ? void 0 : contentElement.id) { selectors.push(`[aria-controls~="${contentElement.id}"]`); } if (baseElement2 == null ? void 0 : baseElement2.id) { selectors.push(`[aria-controls~="${baseElement2.id}"]`); } if (!selectors.length) return [...elements, baseElement2]; const selector = selectors.join(","); const controlElements = doc.querySelectorAll(selector); return [...elements, ...controlElements]; }, // The combobox popover should focus on the combobox input when it hides, // unless the event was triggered by a click outside the popover, in which // case the input shouldn't be re-focused. autoFocusOnHide(element) { if (_misc.isFalsyBooleanCallback.call(void 0, autoFocusOnHide, element)) return false; if (hiddenByClickOutsideRef.current) { hiddenByClickOutsideRef.current = false; return false; } return true; }, // Make sure we don't hide the popover when the user interacts with the // combobox cancel or the combobox disclosure buttons. They will have the // aria-controls attribute pointing to either the combobox input or the // combobox popover elements. hideOnInteractOutside(event) { var _a, _b; const state = store == null ? void 0 : store.getState(); const contentId = (_a = state == null ? void 0 : state.contentElement) == null ? void 0 : _a.id; const baseId = (_b = state == null ? void 0 : state.baseElement) == null ? void 0 : _b.id; if (isController(event.target, contentId, baseId)) return false; const result = typeof hideOnInteractOutside === "function" ? hideOnInteractOutside(event) : hideOnInteractOutside; if (result) { hiddenByClickOutsideRef.current = event.type === "click"; } return result; } }); return props; } ); var ComboboxPopover = _6SC6IEJJcjs.createDialogComponent.call(void 0, _SQLDFLTEcjs.forwardRef.call(void 0, function ComboboxPopover2(props) { const htmlProps = useComboboxPopover(props); return _SQLDFLTEcjs.createElement.call(void 0, TagName, htmlProps); }), _IOFHSY3Lcjs.useComboboxProviderContext ); exports.ComboboxPopover = ComboboxPopover; exports.useComboboxPopover = useComboboxPopover;