{"$schema":"https:\/\/ui.particle.academy\/schema\/registry-item.json","name":"skip-link","type":"registry:ui","title":"SkipLink","description":"A \"Skip to content\" link (WCAG 2.4.1) - hidden until focused but still in the tab order, moves focus to the target, and keeps a hash router out of it.","package":"react-fancy","dependencies":[],"registryDependencies":[],"files":[{"path":"components\/fancy\/skip-link\/SkipLink.tsx","content":"import { forwardRef, type MouseEvent } from \"react\";\nimport type { SkipLinkProps } from \".\/SkipLink.types\";\n\n\/** Elements that take focus without a tabindex. Giving one `-1` would take it OUT of the tab order. *\/\nconst NATIVELY_FOCUSABLE =\n  \"a[href], area[href], button, input, select, textarea, summary, iframe, [contenteditable=''], [contenteditable='true']\";\n\n\/**\n * A \"Skip to content\" link (WCAG 2.4.1, Bypass Blocks). Render it first in the\n * page, before the header, so it is the first tab stop.\n *\n * Visually hidden until it is focused, then shown at the top-start corner in\n * the theme's surface and text colours. Both looks ship in `styles.css`, keyed\n * on the handle rather than on Tailwind classes, so the link is hidden even in\n * an app that has not @sourced the kit: an un-compiled `sr-only` would leave a\n * stray link visible at the top of every page.\n *\n * Activating it moves FOCUS to the target, not just the scroll position: a\n * plain `#main` link scrolls, but focus stays on the link in some browsers, so\n * the next Tab lands back in the header. A target that cannot take focus\n * (a `<main>`, a `<div>`) gets `tabIndex=-1` first, if it has no tabindex of\n * its own. The click is handled here, so a hash router never sees the\n * fragment; with no element of that id, the browser's own navigation runs.\n *\/\nexport const SkipLink = forwardRef<HTMLAnchorElement, SkipLinkProps>(\n  ({ targetId = \"main\", href, label = \"Skip to content\", onClick, ...props }, ref) => {\n    const to = href ?? `#${targetId}`;\n\n    const handleClick = (e: MouseEvent<HTMLAnchorElement>) => {\n      onClick?.(e);\n      if (e.defaultPrevented || !to.startsWith(\"#\")) return;\n      const target = document.getElementById(decodeURIComponent(to.slice(1)));\n      if (!target) return;\n      e.preventDefault();\n      if (!target.hasAttribute(\"tabindex\") && !target.matches(NATIVELY_FOCUSABLE)) {\n        target.setAttribute(\"tabindex\", \"-1\");\n      }\n      target.focus();\n      target.scrollIntoView?.({ block: \"start\" });\n    };\n\n    return (\n      <a\n        {...props}\n        ref={ref}\n        href={to}\n        onClick={handleClick}\n        data-skip-link=\"\"\n        data-react-fancy-skip-link=\"\"\n      >\n        {label}\n      <\/a>\n    );\n  },\n);\n\nSkipLink.displayName = \"SkipLink\";\n","type":"registry:ui","target":"components\/fancy\/skip-link\/SkipLink.tsx"},{"path":"components\/fancy\/skip-link\/SkipLink.types.ts","content":"import type { AnchorHTMLAttributes, ReactNode } from \"react\";\n\nexport interface SkipLinkProps extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, \"children\"> {\n  \/**\n   * The id of the element to skip to, without `#`. Default `\"main\"`, so\n   * `<main id=\"main\">` works with no props at all.\n   *\/\n  targetId?: string;\n  \/**\n   * The fragment to link to, `\"#content\"`. Wins over `targetId` when both are\n   * given. A non-fragment href is rendered as given and left to the browser.\n   *\/\n  href?: string;\n  \/** The link text. Default `\"Skip to content\"`. *\/\n  label?: ReactNode;\n}\n","type":"registry:ui","target":"components\/fancy\/skip-link\/SkipLink.types.ts"},{"path":"components\/fancy\/skip-link\/index.ts","content":"export { SkipLink } from \".\/SkipLink\";\nexport type { SkipLinkProps } from \".\/SkipLink.types\";\n","type":"registry:ui","target":"components\/fancy\/skip-link\/index.ts"}]}