{"version":3,"file":"overlayFocus-C0uUNfbv.cjs","sources":["../src/utils/overlayFocus.tsx"],"sourcesContent":["'use client';\nimport { useLayoutEffect } from 'react';\n\n/**\n * Remembers the element that had focus when its parent mounted and gives it\n * focus back on unmount. Radix only restores focus to a `<Trigger>`, so a\n * controlled overlay opened from anywhere else dropped focus to <body> on close.\n * Render it once inside the overlay's content.\n */\nexport function ReturnFocus() {\n  useLayoutEffect(() => {\n    const active = document.activeElement;\n    const opener = active instanceof HTMLElement && active !== document.body ? active : null;\n    return () => {\n      if (opener && opener.isConnected) opener.focus({ preventScroll: true });\n    };\n  }, []);\n  return null;\n}\n\nconst FIELD = 'input:not([type=\"hidden\"]):not(:disabled),select:not(:disabled),textarea:not(:disabled),[role=\"combobox\"]:not([aria-disabled=\"true\"]):not([data-disabled])';\nconst TABBABLE = 'a[href],button:not(:disabled),[tabindex]:not([tabindex=\"-1\"])';\n\n/**\n * Default initial focus for Dialog / Drawer: the first form field in the body,\n * otherwise the first control in the body, otherwise Radix's default (the\n * header Close button). Call from `onOpenAutoFocus`; honours `preventDefault`.\n */\nexport function focusFirstField(event: Event, bodySelector: string) {\n  if (event.defaultPrevented) return;\n  const content = event.target as HTMLElement | null;\n  const body = content?.querySelector<HTMLElement>(bodySelector);\n  const first = body?.querySelector<HTMLElement>(FIELD) ?? body?.querySelector<HTMLElement>(TABBABLE);\n  if (!first) return;\n  event.preventDefault();\n  first.focus();\n}\n"],"names":["ReturnFocus","useLayoutEffect","active","opener","FIELD","TABBABLE","focusFirstField","event","bodySelector","content","body","first"],"mappings":"mDASO,SAASA,GAAc,CAC5BC,OAAAA,EAAAA,gBAAgB,IAAM,CACpB,MAAMC,EAAS,SAAS,cAClBC,EAASD,aAAkB,aAAeA,IAAW,SAAS,KAAOA,EAAS,KACpF,MAAO,IAAM,CACPC,GAAUA,EAAO,aAAaA,EAAO,MAAM,CAAE,cAAe,GAAM,CACxE,CACF,EAAG,CAAA,CAAE,EACE,IACT,CAEA,MAAMC,EAAQ,6JACRC,EAAW,gEAOV,SAASC,EAAgBC,EAAcC,EAAsB,CAClE,GAAID,EAAM,iBAAkB,OAC5B,MAAME,EAAUF,EAAM,OAChBG,EAAOD,GAAA,YAAAA,EAAS,cAA2BD,GAC3CG,GAAQD,GAAA,YAAAA,EAAM,cAA2BN,MAAUM,GAAA,YAAAA,EAAM,cAA2BL,IACrFM,IACLJ,EAAM,eAAA,EACNI,EAAM,MAAA,EACR"}