{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "focus-trap",
  "title": "Focus Trap",
  "description": "Keyboard focus held inside one subtree, for the overlays you built yourself — with the tab-stop predicate, the tab order and the nesting stack exported as plain functions rather than sealed inside a component. Reach for it wherever the overlay is yours rather than a primitive's: a command palette, an inspector panel over a canvas, a side sheet, a full-screen confirm step, a popover you positioned by hand, a lightbox, an onboarding step, a context menu on a diagram, anything assembled out of a plain div because the primitive did not fit. Common asks it answers: \"focus trap react\", \"react focus trap component\", \"shadcn focus trap\", \"trap focus in modal react\", \"focus trap hook\", \"useFocusTrap\", \"focus trap without radix\", \"focus trap vanilla javascript\", \"keyboard focus escapes my modal\", \"tab out of modal react\", \"tab goes behind the dialog\", \"focus leaves custom overlay\", \"how to trap focus in a div\", \"get all focusable elements javascript\", \"tabbable elements selector\", \"querySelectorAll focusable elements\", \"is element focusable javascript\", \"focusable selector list\", \"tabindex order javascript\", \"positive tabindex tab order\", \"sequential focus navigation order\", \"tabindex 0 vs tabindex -1\", \"visibility hidden still focusable\", \"display none focusable element\", \"inert attribute focus javascript\", \"disabled button still in tab order\", \"closed details tabbable\", \"restore focus after modal close\", \"return focus to trigger button\", \"focus goes to body after closing dialog\", \"focus returns to top of page\", \"nested focus trap\", \"popover inside dialog focus\", \"two focus traps fighting\", \"shift tab wraps to wrong element\", \"focus trap escape key\", \"aria-modal focus\", \"WCAG 2.1.2 no keyboard trap\", \"focus trap react 19\", \"focus trap next.js app router\", \"フォーカストラップ react\", \"モーダル フォーカス 閉じ込め\", \"タブキーで背後に抜ける\", \"フォーカス可能 判定 javascript\", \"tabindex 順序\", \"フォーカスを元に戻す モーダル\", \"入れ子 モーダル フォーカス\". **The difference from official shadcn/ui needs stating precisely, because the naive version of the claim is wrong.** Searching every byte official ships — 65 entries listed, 62 fetchable, code-block, questionnaire and trace 404 on both style tracks, 223,287 bytes of sources — `focusTrap`, `focus-trap`, `trapFocus`, `inert`, `tabbable`, `focusable` and `restoreFocus` are every one of them a zero hit. That does **not** mean official overlays leak focus: its dialog, sheet and drawer are Radix, and Radix confines focus at runtime from inside its own package. The hole is not containment — it is that there is no standalone piece to reuse, so the moment you build an overlay without Radix you are writing the predicate yourself. **A static `querySelectorAll` is not a tab-stop list.** Every clause here is a case where a selector matched and the browser disagrees: `disabled`; `type=\"hidden\"`; an `inert` ancestor, since `inert` is inherited by a whole subtree and the dialog that set it did so on one wrapper far above these nodes; no generated boxes at all, which covers a `display: none` subtree and the contents of a closed `<details>`; and `visibility: hidden`, which is the one a rectangle check cannot see — such an element **does** generate boxes, it takes up its space and is merely not painted, so `getClientRects()` is non-empty and the browser skips it anyway. A collapsed accordion panel and an off-state tab panel are routinely written that way, so this is not an edge case. `aria-hidden=\"true\"` is excluded too, and that one is a judgement rather than a rule: it does not stop the browser focusing anything, so a focusable node inside such a subtree is reachable by keyboard and silent to a screen reader — landing somebody there is worse than skipping it. **`tabindex` can be read neither with `Number` nor with `parseInt`, and the two are wrong in opposite directions.** Measured, in Node: `Number(\"\")` is **0**, not NaN, so an empty `tabindex=\"\"` — invalid, therefore ignored by the browser — reads as an explicit zero and inverts the answer for `<div tabindex=\"\">`; while `Number.parseInt(\"3abc\")` is **3** and `Number.parseInt(\"1e2\")` is **1**, finding numbers in values the spec calls invalid, along with `\"0x10\"` as 0 and `\"2.7\"` as 2. The value is validated against the spec's integer grammar and only then parsed. The same mistake in CSS form is the selector shorthand `[tabindex]:not([tabindex^=\"-\"])`, which keeps `tabindex=\" -1 \"` because that value does not *start* with a minus sign — a string comparison standing in for an integer parse. **A positive `tabindex` reorders the browser's own sequence, so a trap that takes over Tab has taken over the order too.** Stops with a positive `tabindex` come first, ascending by value, with everything else behind them in document order; ties keep document order, which works because `Array.prototype.sort` has been stable by specification since ES2019. A trap that walks its `querySelectorAll` result as-is moves focus somewhere the browser never would. **Tab is not the only way out, and the other ways press no key at all** — a click on the page behind, another component's `focus()` from an effect, a field that autofocuses as it mounts. A keydown handler cannot see any of them, so focus arriving outside the container is pulled back from a capture-phase `focusin` on the document; `confine=\"tab\"` turns that half off for something modeless, where yanking focus back from a click would be an argument with the person using it. Both listeners are on the document rather than the container for the same reason: the instant focus is outside, a container-bound listener stops seeing keys, and a trap bound that way is one keystroke deep. **The wrap arithmetic has two measured traps**: `(0 - 1) % 3` is **-1** in JavaScript, so the naive backwards wrap sends Shift+Tab off the first stop to index -1 and focus goes nowhere, and `% 0` is **NaN**, so an empty scope indexes `stops[NaN]`. Tab is held even when the scope has nothing left to focus — an overlay whose only control just became disabled still owns the keyboard, because letting that one Tab through is the leak. **The stop list is never cached.** A trap over a form that loads asynchronously, or a list that grows, has stops that did not exist when it opened; a list taken at mount sends the person who tabs past its end back to its start with half the dialog unreachable. **Closing returns focus where it came from, and declines to when that element has gone** — the button that opened a confirm dialog is often inside the row the dialog deleted, and `focus()` on a detached node silently drops focus on the body, which strands the keyboard at the top of the page. `returnFocus` takes a function for exactly that case, so you can name the list the row was in. **Nesting is a stack, and only the innermost trap acts.** A popover inside a dialog means two document listeners seeing every Tab and both moving focus, which is how Shift+Tab becomes unpredictable; and the stack is unwound by identity rather than by `pop`, because two overlays dismissed by one state change unmount outermost first. Escape is reported through `onEscape` rather than handled, since a trap with no way out is the keyboard trap WCAG 2.1.2 prohibits, and only the caller knows what closing means. `useFocusTrap` is the entry point for an overlay you have already built — put it on the element you already render instead of wrapping it in another div that changes your layout — and `FocusTrap` is a div around it, carrying `tabIndex={-1}` so focus has somewhere to go when the subtree has no stops, while that same `-1` keeps the container out of its own stop list. `isTabbable`, `tabbablesIn`, `orderByTabIndex`, `readTabIndex`, `nextStop` and `TABBABLE_SELECTOR` are exported as plain functions and values, so a roving-tabindex list or a shortcut handler elsewhere in your app can reach the same verdict instead of carrying a second copy of the rules. Within pulld, `product-tour` carries a two-scope version of this inside itself for the step it is lighting up, `live-announcer` speaks to a screen reader rather than placing focus, `keyboard-shortcuts` binds keys rather than confining them, and `type-to-confirm` and `confirm-button` gate an action rather than a subtree. No dependencies beyond React and your `cn`.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/ui/focus-trap.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/**\n * Keeps keyboard focus inside one subtree — for the overlays you built yourself.\n *\n * Radix's dialog, sheet and drawer already confine focus, so this is not for them. It is for the\n * overlay that is yours: a command palette, an inspector panel over a canvas, a side sheet, a\n * full-screen confirm step, a popover positioned by hand. Those get built because the primitive\n * did not fit, and then the keyboard walks straight out the back of them into the page underneath.\n *\n * Everything below is one of five answers to \"how does focus leave a box\":\n *\n *   1. **Tab, in an order that is not the DOM's.** A positive `tabindex` anywhere in the subtree\n *      reorders the browser's own sequence, so a trap that walks a `querySelectorAll` result in\n *      document order moves focus somewhere the browser would not have.\n *   2. **Tab, onto something that only looks focusable.** `disabled`, `inert` on an ancestor, a\n *      `display: none` subtree, a closed `<details>`, `visibility: hidden`, `type=\"hidden\"` — a\n *      static selector match says yes to all of them and the browser says no to every one.\n *   3. **Not Tab at all.** A click outside, a programmatic `focus()` from some other component's\n *      effect, an autofocusing field that mounts late. No key was pressed, so a keydown handler\n *      never runs.\n *   4. **Closing.** Focus has to go back to whatever opened the overlay, and that element is\n *      sometimes gone — the row whose \"Delete\" button opened the dialog is the row the dialog\n *      deleted.\n *   5. **Nesting.** A popover inside a dialog. Two traps both listening on the document fight over\n *      every Tab, and the outer one winning means the inner one is decorative.\n *\n * The pieces are exported as plain functions, because the hard part is the tab-stop predicate and\n * it is worth being able to call it — and test it — on its own.\n */\n\n/**\n * The elements a tab stop can be, before any of the conditions that disqualify one.\n *\n * Deliberately wider than it needs to be, and then narrowed by {@link isTabbable}. The tempting\n * version does both at once — `button:not([disabled])`, `[tabindex]:not([tabindex^=\"-\"])` — and\n * that last clause is a string comparison standing in for an integer parse. `tabindex=\" -1 \"` is a\n * negative tab index that does not start with a minus sign, so the selector keeps it and the\n * browser skips it. Collect on tag and attribute presence; decide in code.\n */\nexport const TABBABLE_SELECTOR = [\n  \"a[href]\",\n  \"area[href]\",\n  \"button\",\n  \"input\",\n  \"select\",\n  \"textarea\",\n  \"summary\",\n  \"iframe\",\n  \"object\",\n  \"embed\",\n  \"audio[controls]\",\n  \"video[controls]\",\n  '[contenteditable]:not([contenteditable=\"false\"])',\n  \"[tabindex]\",\n].join(\",\")\n\n/**\n * An HTML integer attribute, or `null` for \"no usable value\".\n *\n * Both obvious readings of `tabindex` are wrong, in opposite directions, and each has a case that\n * matters. Measured, in Node:\n *\n *   - `Number(\"\")` is **0**, not `NaN`. An empty `tabindex=\"\"` is not a valid integer, so the\n *     browser ignores the attribute — but `Number` reads it as an explicit zero, which inverts the\n *     answer for `<div tabindex=\"\">`: ignored means \"not a tab stop\", zero means \"is one\".\n *   - `Number.parseInt(\"3abc\")` is **3** and `Number.parseInt(\"1e2\")` is **1**, where the spec\n *     calls both values invalid. `parseInt` also takes `\"0x10\"` as 0 and `\"2.7\"` as 2.\n *\n * So the value is validated against the spec's integer grammar first (optional sign, digits, ASCII\n * whitespace allowed either side) and only then parsed. `\"+3\"` and `\" 3 \"` are valid and come back\n * as 3; `\"\"`, `\"3abc\"`, `\"1e2\"`, `\"2.7\"`, `\"0x10\"` and `\"abc\"` all come back as `null`.\n */\nexport function readTabIndex(raw: string | null | undefined): number | null {\n  if (raw === null || raw === undefined) return null\n  if (!/^[ \\t\\n\\f\\r]*[+-]?\\d+[ \\t\\n\\f\\r]*$/.test(raw)) return null\n  const value = Number.parseInt(raw, 10)\n  return Number.isNaN(value) ? null : value\n}\n\n/** The `tabindex` an element declares, or `null` if it declares none that parses. */\nfunction declaredTabIndex(node: Element): number | null {\n  return readTabIndex(node.getAttribute?.(\"tabindex\"))\n}\n\n/**\n * Whether `node` is somewhere the browser would put focus when Tab is pressed.\n *\n * Each clause below is a case where the selector matched and the browser disagrees. The order is\n * cheapest first; the last two are the ones that need to look at rendering.\n *\n * `aria-hidden=\"true\"` is the one judgement call here rather than a rule. It does not actually stop\n * the browser focusing an element — a focusable node inside an `aria-hidden` subtree is reachable\n * by keyboard and invisible to a screen reader, which is a bug wherever it occurs. Treating it as\n * not-a-stop is the reading that does not land a screen-reader user on a control their software\n * will not announce.\n */\nexport function isTabbable(node: Element): boolean {\n  if (!node) return false\n\n  // A negative tab index is focusable but not tabbable — that is the whole point of `-1`, and it is\n  // what the trap's own container uses to be a focus target without becoming a stop inside itself.\n  const declared = declaredTabIndex(node)\n  if (declared !== null && declared < 0) return false\n\n  // `disabled` on a form control. Not a concern for `a[href]`, where the attribute means nothing,\n  // and harmless to check there.\n  if (node.hasAttribute?.(\"disabled\")) return false\n\n  // A hidden input is a transport for a value, not a control.\n  if (node.getAttribute?.(\"type\")?.toLowerCase() === \"hidden\") return false\n\n  // `inert` is inherited by the whole subtree, so the element's own attribute is not the question —\n  // a dialog marking the page behind it inert does so on one wrapper far above these nodes.\n  if (node.closest?.(\"[inert]\")) return false\n  if (node.closest?.('[aria-hidden=\"true\"]')) return false\n\n  // \"Is it rendered\" in the cheapest honest form: a node in a `display: none` subtree, or inside a\n  // closed `<details>`, generates no boxes at all. Agreeing with the browser's own tab order is\n  // what makes this better than walking computed styles up the tree.\n  //\n  // Absent on a node that was never in a document — the server's answer, and a test's — and that\n  // case reads as \"not measured\" rather than \"not rendered\".\n  if (typeof node.getClientRects === \"function\" && node.getClientRects().length === 0) return false\n\n  // `visibility: hidden` is the case the box check cannot see, and it is not an edge case: a\n  // collapsed accordion panel or an off-state tab panel is routinely written this way, and such an\n  // element **generates boxes** — it takes up its space, it is merely not painted. So\n  // `getClientRects()` is non-empty and the browser still skips it. Checked last because it is the\n  // only clause that costs a style resolution.\n  if (typeof getComputedStyle === \"function\") {\n    const visibility = getComputedStyle(node)?.visibility\n    if (visibility === \"hidden\" || visibility === \"collapse\") return false\n  }\n\n  return true\n}\n\n/**\n * The browser's sequential focus navigation order for a set of elements already in document order.\n *\n * Elements with a positive `tabindex` come first, ascending by value; everything else keeps\n * document order behind them. This is the rule that makes a positive `tabindex` a mistake in most\n * code — it jumps the queue globally — and the rule a trap has to reproduce, since a trap that\n * takes over Tab has taken over the order too.\n *\n * The sort is relied upon to be stable, so two elements with `tabindex=\"2\"` stay in the order they\n * appear in the document. `Array.prototype.sort` has been stable by specification since ES2019\n * (verified here: twelve items keyed `i % 3` come out with each group in its original order).\n */\nexport function orderByTabIndex<T extends Element>(nodes: readonly T[]): T[] {\n  const jumpers: { node: T; index: number; at: number }[] = []\n  const inOrder: T[] = []\n  nodes.forEach((node, at) => {\n    const declared = declaredTabIndex(node)\n    if (declared !== null && declared > 0) jumpers.push({ node, index: declared, at })\n    else inOrder.push(node)\n  })\n  jumpers.sort((a, b) => a.index - b.index || a.at - b.at)\n  return [...jumpers.map((entry) => entry.node), ...inOrder]\n}\n\n/**\n * The tab stops inside `root`, in the order Tab would visit them — plus `root` itself if it is one.\n *\n * Never cached. A trap over a form that loads asynchronously, or a list that grows, has stops that\n * did not exist when it opened; a list taken once at mount cannot reach them, and the person who\n * tabs past the end of the stale list is sent back to its start with half the dialog unreachable.\n * Recomputed on every Tab instead, which is one `querySelectorAll` per keystroke.\n */\nexport function tabbablesIn(root: Element | null | undefined): HTMLElement[] {\n  if (!root || typeof root.querySelectorAll !== \"function\") return []\n  const found = Array.from(root.querySelectorAll(TABBABLE_SELECTOR)) as HTMLElement[]\n  // A root can be the control rather than contain one — a trap placed directly on a single button —\n  // and a scope of descendants only would have nothing in it.\n  if (root.matches?.(TABBABLE_SELECTOR)) found.unshift(root as HTMLElement)\n  return orderByTabIndex(found.filter(isTabbable))\n}\n\n/**\n * The index to move to, or `null` when there is nowhere to go.\n *\n * Two arithmetic traps, both measured: `(0 - 1) % 3` is **-1** in JavaScript, not 2, so the naive\n * wrap sends Shift+Tab from the first stop to index −1 and focus goes nowhere; and `% 0` is\n * **NaN**, so an empty scope produces `stops[NaN]`. Adding `count` before the modulo fixes the\n * first and the `count <= 0` guard fixes the second.\n *\n * `at < 0` is the ordinary case on the first Tab, when focus is on the container itself rather than\n * on a stop: forwards that enters at the first stop, backwards at the last.\n */\nexport function nextStop(count: number, at: number, delta: number): number | null {\n  if (count <= 0) return null\n  if (at < 0) return delta < 0 ? count - 1 : 0\n  return (at + delta + count) % count\n}\n\n/**\n * The traps currently mounted and active, outermost first.\n *\n * Every trap listens on the document, because that is the only place a trap can listen: the moment\n * focus is anywhere other than inside the container, a listener bound to the container stops\n * seeing keys. Which means that with a popover open inside a dialog, both of them see every Tab,\n * and both try to move focus — the dialog pulling it back to the dialog's first stop, the popover\n * to the popover's. Focus ends up wherever the second listener ran, and Shift+Tab becomes\n * unpredictable.\n *\n * So only the last one to open acts. Module scope is the right place for this because it is a fact\n * about the page, not about any one component, and nesting is between two different instances. It\n * is only ever touched inside effects, so a server render never populates it.\n */\nconst TRAPS: object[] = []\n\nconst isTopmost = (id: object) => TRAPS.length > 0 && TRAPS[TRAPS.length - 1] === id\n\n/** Where focus goes when the trap opens. A function is called at open time and may return null. */\nexport type InitialFocus = \"first\" | \"container\" | \"none\" | (() => HTMLElement | null)\n\n/**\n * Where focus goes when the trap closes. `true` means \"back where it was\"; a function names a\n * target, which is how you survive the case where \"where it was\" has been removed.\n */\nexport type ReturnFocus = boolean | (() => HTMLElement | null)\n\nexport interface FocusTrapOptions {\n  /** Off leaves the subtree alone, so an overlay can stay mounted while closed. Default `true`. */\n  active?: boolean\n  /**\n   * Which escape routes to close.\n   *\n   * `\"all\"` (default) also pulls focus back when it lands outside without a Tab — a click on the\n   * page behind, another component's `focus()` call, a field that autofocuses as it mounts. That is\n   * what a modal overlay means, and it is the half a keydown handler cannot do.\n   *\n   * `\"tab\"` handles only the key. Use it for something modeless, where clicking the page behind is\n   * allowed and yanking focus back from it would be an argument with the person using it.\n   */\n  confine?: \"tab\" | \"all\"\n  /** Default `\"first\"`: the first stop inside, falling back to the container. */\n  initialFocus?: InitialFocus\n  /** Default `true`. */\n  returnFocus?: ReturnFocus\n  /** Called on Escape. Without it, Escape is left to whatever else is listening. */\n  onEscape?: () => void\n}\n\n/**\n * Confines focus to `ref`'s subtree while `active`.\n *\n * The hook rather than the component is the point of entry for an overlay you have already built —\n * put it on the element you already render, instead of wrapping it in another `div` that changes\n * your layout.\n */\nexport function useFocusTrap<T extends HTMLElement>(\n  ref: React.RefObject<T | null>,\n  { active = true, confine = \"all\", initialFocus = \"first\", returnFocus = true, onEscape }: FocusTrapOptions = {}\n): void {\n  /**\n   * The options, always this render's, for the listeners below to read.\n   *\n   * Kept in a ref updated after every render rather than listed as effect dependencies, so that\n   * passing `onEscape={() => setOpen(false)}` — a new function identity every render, which is how\n   * everybody writes it — does not tear the trap down and rebuild it on each render. Rebuilding\n   * would re-run the open sequence, and the open sequence moves focus: the person would be returned\n   * to the first field every time anything above them re-rendered.\n   */\n  const latest = React.useRef({ confine, initialFocus, returnFocus, onEscape })\n  React.useEffect(() => {\n    latest.current = { confine, initialFocus, returnFocus, onEscape }\n  })\n\n  // This instance's identity in TRAPS. An object rather than a string, so two traps are never\n  // mistaken for each other however they were rendered.\n  const idRef = React.useRef<object>({})\n\n  React.useEffect(() => {\n    if (!active || typeof document === \"undefined\") return\n    const id = idRef.current\n    TRAPS.push(id)\n\n    // Read before anything is focused, which is the only moment it is still true.\n    const openedFrom = document.activeElement as HTMLElement | null\n\n    const container = ref.current\n    const wanted = latest.current.initialFocus\n    if (container && wanted !== \"none\") {\n      const target =\n        typeof wanted === \"function\"\n          ? wanted()\n          : wanted === \"container\"\n            ? container\n            : (tabbablesIn(container)[0] ?? container)\n      target?.focus?.()\n    }\n\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (!isTopmost(id)) return\n      if (event.key === \"Escape\") {\n        const escape = latest.current.onEscape\n        if (!escape) return\n        event.preventDefault()\n        escape()\n        return\n      }\n      if (event.key !== \"Tab\") return\n      const node = ref.current\n      if (!node) return\n      const stops = tabbablesIn(node)\n      // Prevented even when the move stays inside, because the order being this one and not the\n      // document's is the entire behaviour — and prevented when there is nowhere to go at all,\n      // since letting that Tab through is precisely the leak this exists to stop. An overlay whose\n      // only control has just become disabled still holds the keyboard.\n      event.preventDefault()\n      if (stops.length === 0) {\n        node.focus?.()\n        return\n      }\n      const focused = document.activeElement as HTMLElement | null\n      const at = focused ? stops.indexOf(focused) : -1\n      const to = nextStop(stops.length, at, event.shiftKey ? -1 : 1)\n      if (to !== null) stops[to]?.focus?.()\n    }\n\n    /**\n     * The half that has nothing to do with keys.\n     *\n     * Focus arriving outside the container is pulled back to its first stop. Capture phase and on\n     * the document for the same reason as the keys: by the time this matters, focus is somewhere\n     * else entirely.\n     *\n     * This cannot loop. Pulling focus back fires another `focusin`, and that one is inside the\n     * container, so it returns at the containment check. If the pull fails — nothing inside can\n     * take focus — no `focusin` is dispatched at all.\n     */\n    const onFocusIn = (event: FocusEvent) => {\n      if (latest.current.confine !== \"all\") return\n      if (!isTopmost(id)) return\n      const node = ref.current\n      if (!node) return\n      const target = event.target as Node | null\n      if (target && node.contains?.(target)) return\n      const stops = tabbablesIn(node)\n      ;(stops[0] ?? node).focus?.()\n    }\n\n    document.addEventListener(\"keydown\", onKeyDown, true)\n    document.addEventListener(\"focusin\", onFocusIn, true)\n\n    return () => {\n      document.removeEventListener(\"keydown\", onKeyDown, true)\n      document.removeEventListener(\"focusin\", onFocusIn, true)\n      // `lastIndexOf` and a splice rather than a pop: a trap is not always the one on top when it\n      // closes. Two overlays dismissed by the same state change unmount in render order, which is\n      // outermost first.\n      const at = TRAPS.lastIndexOf(id)\n      if (at !== -1) TRAPS.splice(at, 1)\n\n      const how = latest.current.returnFocus\n      const target = typeof how === \"function\" ? how() : how ? openedFrom : null\n      /**\n       * Nothing is focused if the target has left the document, and that is the common case rather\n       * than a defensive check: the button that opened a confirm dialog is often inside the row the\n       * dialog was confirming the deletion of. Calling `focus()` on a detached node silently moves\n       * focus to the body, which drops the keyboard at the top of the page — worse than leaving it\n       * alone, and indistinguishable from it in a test. Pass a function to `returnFocus` to name\n       * somewhere that will still exist, such as the list the row was in.\n       */\n      if (target && (target.isConnected ?? true)) target.focus?.()\n    }\n    // `ref` is stable and the options are read through `latest`, so this runs on open and close and\n    // at no other time — see the note on `latest` above.\n  }, [active, ref])\n}\n\nexport interface FocusTrapProps extends React.ComponentPropsWithoutRef<\"div\">, FocusTrapOptions {}\n\n/**\n * A `div` that holds the keyboard.\n *\n * `tabIndex={-1}` is on it by default and is load-bearing twice over: it makes the container itself\n * a place focus can be put — needed when the subtree has no stops yet, or none left — while\n * `isTabbable` reads that same `-1` as \"not a stop\", so the container never becomes a stop within\n * its own scope. Override it through props if you have a reason.\n */\nexport function FocusTrap({\n  active,\n  confine,\n  initialFocus,\n  returnFocus,\n  onEscape,\n  className,\n  ...props\n}: FocusTrapProps) {\n  const ref = React.useRef<HTMLDivElement | null>(null)\n  useFocusTrap(ref, { active, confine, initialFocus, returnFocus, onEscape })\n  return <div ref={ref} tabIndex={-1} className={cn(\"outline-none\", className)} {...props} />\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui",
  "docs": "Install any pulld component by name: add \"@pulld\": \"https://pulld.pages.dev/r/{name}.json\" to the registries block in components.json, then `npx shadcn add @pulld/<name>`. All 149 components: https://pulld.pages.dev/?utm_source=cli"
}
