{"version":3,"file":"appendToSandbox.cjs","names":["sandboxAttribute","exports","appendToSandbox","element","setAttribute","document","body","append"],"sources":["../../../src/test-utils/appendToSandbox.ts"],"sourcesContent":["/*!\n * Copyright (c) 2026-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nexport const sandboxAttribute = \"data-sandbox-root\";\n\n/**\n * Attaches a element to `document.body` and tags it with a data sandbox attribute so the global browser-test `afterEach` (in `vitest-browser-setup.ts`) can remove it between tests.\n *\n * ### Why this exists\n *\n * A handful of tests build DOM nodes imperatively (`document.createElement`) and append them directly to `document.body` to exercise hooks and utilities that read layout/scroll/visibility off real DOM (e.g. `useScrollState`, `useElementAtContainerEdge`, `SkipToContent`'s external-focus scenarios, `UiShell`'s web-component bootstrapping). Those nodes live OUTSIDE React's render tree, so vitest-browser-react's auto-cleanup cannot remove them — without some form of cleanup they leak from one test to the next.\n *\n * ### Why not `document.body.innerHTML = \"\"` in a global afterEach\n *\n * It breaks every component that uses portals.\n * MUI portals (Dialog, Select, Tooltip, DatePicker, Autocomplete listbox, Drawer, Menu, …) attach their content to `document.body` via `ReactDOM.createPortal`. Wiping body while React is still mid-unmount triggers `NotFoundError: Failed to execute 'removeChild' on 'Node'` because React's reconciler tries to remove portal children that our wipe already removed.\n *\n * ### Usage\n *\n * ```ts\n * const containerElement = document.createElement(\"div\");\n * appendToSandbox(containerElement);\n * ...assertions\n * no per-file afterEach needed — the global setup wipes tagged nodes.\n * ```\n */\nexport const appendToSandbox = <Element extends globalThis.Element>(\n  element: Element,\n): Element => {\n  element.setAttribute(sandboxAttribute, \"\");\n  document.body.append(element);\n  return element;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEO,MAAMA,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,mBAAmB;AAuB5C,MAAME,eAAe,GAC1BC,OAAgB,IACJ;EACZA,OAAO,CAACC,YAAY,CAACJ,gBAAgB,EAAE,EAAE,CAAC;EAC1CK,QAAQ,CAACC,IAAI,CAACC,MAAM,CAACJ,OAAO,CAAC;EAC7B,OAAOA,OAAO;AAChB,CAAC;AAACF,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}