summaryrefslogtreecommitdiff
path: root/apps/web/src/components/ui/visually-hidden.tsx
blob: 7d6fc435c4fda7127acaac98c91ed654bac31236 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"use client";

import * as React from "react";
import { cn } from "../../lib/utils";

/**
 * VisuallyHidden component provides content that is accessible to screen readers
 * but visually hidden from sighted users. This is useful for providing context
 * or labels that are necessary for accessibility but would be redundant visually.
 * 
 * Based on the Radix UI VisuallyHidden primitive pattern.
 */
const VisuallyHidden = React.forwardRef<
  HTMLSpanElement,
  React.ComponentPropsWithoutRef<"span">
>(({ className, ...props }, ref) => (
  <span
    ref={ref}
    className={cn(
      // Screen reader only styles - visually hidden but accessible
      "absolute w-px h-px p-0 -m-px overflow-hidden whitespace-nowrap border-0",
      // Alternative approach using sr-only if preferred
      // "sr-only",
      className
    )}
    {...props}
  />
));

VisuallyHidden.displayName = "VisuallyHidden";

export { VisuallyHidden };