{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "input-modality",
  "title": "useInputModality",
  "description": "Marks <html data-input> as keyboard or pointer, so menu items ring only for keyboard readers.",
  "files": [
    {
      "path": "lib/input-modality.ts",
      "content": "'use client';\n\nimport { useEffect } from 'react';\n\n/*\n * The last way the reader moved: `keyboard` or `pointer`, on <html data-input>.\n * Radix moves focus to the menu item under the pointer, and browsers then match\n * :focus-visible for pointer readers too, so menus cannot tell the two apart\n * from focus alone. Menu items draw their focus ring only for keyboard readers.\n */\nlet listening = false;\n\nfunction mark(input: 'keyboard' | 'pointer') {\n  if (document.documentElement.dataset.input !== input) {\n    document.documentElement.dataset.input = input;\n  }\n}\n\nexport function useInputModality() {\n  useEffect(() => {\n    if (listening) return;\n    listening = true;\n    const onKey = () => mark('keyboard');\n    const onPointer = () => mark('pointer');\n    window.addEventListener('keydown', onKey, { capture: true, passive: true });\n    window.addEventListener('pointerdown', onPointer, { capture: true, passive: true });\n    window.addEventListener('pointermove', onPointer, { capture: true, passive: true });\n  }, []);\n}\n",
      "type": "registry:lib"
    }
  ],
  "type": "registry:lib"
}