{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "touch-focus",
  "title": "focusContentOnTouch",
  "description": "An onOpenAutoFocus for modals: under a coarse pointer the modal's content takes the focus, not its first field, so the phone keyboard stays shut.",
  "files": [
    {
      "path": "lib/touch-focus.ts",
      "content": "/*\n * Radix focuses a modal's first field when it opens. On a touch screen that\n * opens the software keyboard over the modal before the reader has seen it,\n * so under a coarse pointer the modal's content takes the focus instead, and\n * the reader taps a field to type. A mouse or trackpad keeps Radix's focus.\n *\n * The caller's own onOpenAutoFocus runs first. If it prevents the default, it\n * has moved the focus itself, and this handler leaves it there.\n */\nfunction focusContentOnTouch(handler?: (event: Event) => void) {\n  return (event: Event) => {\n    handler?.(event);\n    // matchMedia can be missing (old embeds) or stubbed without a result (jsdom tests).\n    const coarse = window.matchMedia?.('(pointer: coarse)')?.matches === true;\n    if (event.defaultPrevented || !coarse) {\n      return;\n    }\n    event.preventDefault();\n    // Radix dispatches the event on the content, which it makes focusable (tabindex -1).\n    if (event.currentTarget instanceof HTMLElement) {\n      event.currentTarget.focus({ preventScroll: true });\n    }\n  };\n}\n\nexport { focusContentOnTouch };\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}