Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
React Accessibility Patterns

React Accessibility Patterns

Build accessible React components following WCAG 2.1 guidelines for Google Antigravity apps.

accessibilitya11ywcagreact
by antigravity-team
⭐0Stars
.antigravity
# React Accessibility Patterns for Google Antigravity

Build inclusive, accessible React components following WCAG 2.1 guidelines.

## Accessible Button

```typescript
// components/ui/Button.tsx
import { forwardRef, ButtonHTMLAttributes } from "react";

interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
    loading?: boolean;
    loadingText?: string;
    variant?: "primary" | "secondary" | "destructive";
}

export const Button = forwardRef<HTMLButtonElement, ButtonProps>(
    ({ loading, loadingText, children, disabled, className, ...props }, ref) => {
        return (
            <button
                ref={ref}
                className={`btn ${className || ""}`}
                disabled={disabled || loading}
                aria-disabled={disabled || loading}
                aria-busy={loading}
                {...props}
            >
                {loading ? (
                    <>
                        <span className="sr-only">{loadingText || "Loading"}</span>
                        <svg className="animate-spin h-4 w-4" viewBox="0 0 24 24" aria-hidden="true">
                            <circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" fill="none" />
                        </svg>
                        <span aria-hidden="true">{loadingText || children}</span>
                    </>
                ) : children}
            </button>
        );
    }
);
Button.displayName = "Button";
```

## Accessible Modal

```typescript
// components/ui/Modal.tsx
"use client";

import { useEffect, useRef, useCallback, ReactNode } from "react";
import { createPortal } from "react-dom";

interface ModalProps {
    isOpen: boolean;
    onClose: () => void;
    title: string;
    description?: string;
    children: ReactNode;
}

export function Modal({ isOpen, onClose, title, description, children }: ModalProps) {
    const modalRef = useRef<HTMLDivElement>(null);
    const previousActiveElement = useRef<HTMLElement | null>(null);

    const trapFocus = useCallback((e: KeyboardEvent) => {
        if (!modalRef.current || e.key !== "Tab") return;
        const focusable = modalRef.current.querySelectorAll<HTMLElement>("button, [href], input, select, textarea, [tabindex]:not([tabindex=\"-1\"])");
        const first = focusable[0];
        const last = focusable[focusable.length - 1];
        if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
        else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
    }, []);

    useEffect(() => {
        if (isOpen) {
            previousActiveElement.current = document.activeElement as HTMLElement;
            document.addEventListener("keydown", (e) => { if (e.key === "Escape") onClose(); trapFocus(e); });
            document.body.style.overflow = "hidden";
        }
        return () => {
            document.body.style.overflow = "";
            previousActiveElement.current?.focus();
        };
    }, [isOpen, onClose, trapFocus]);

    if (!isOpen) return null;

    return createPortal(
        <div className="modal-overlay" onClick={onClose}>
            <div ref={modalRef} role="dialog" aria-modal="true" aria-labelledby="modal-title" aria-describedby={description ? "modal-desc" : undefined} className="modal" onClick={(e) => e.stopPropagation()}>
                <h2 id="modal-title">{title}</h2>
                {description && <p id="modal-desc">{description}</p>}
                {children}
                <button onClick={onClose} aria-label="Close">×</button>
            </div>
        </div>,
        document.body
    );
}
```

## Form Field

```typescript
// components/ui/FormField.tsx
import { forwardRef, InputHTMLAttributes } from "react";

interface FormFieldProps extends InputHTMLAttributes<HTMLInputElement> {
    label: string;
    error?: string;
    hint?: string;
    required?: boolean;
}

export const FormField = forwardRef<HTMLInputElement, FormFieldProps>(
    ({ label, error, hint, required, id, ...props }, ref) => {
        const inputId = id || `field-${label.toLowerCase().replace(/\s+/g, "-")}`;
        return (
            <div className={`form-field ${error ? "has-error" : ""}`}>
                <label htmlFor={inputId}>
                    {label}{required && <span aria-hidden="true">*</span>}
                </label>
                {hint && <p id={`${inputId}-hint`}>{hint}</p>}
                <input ref={ref} id={inputId} aria-required={required} aria-invalid={!!error} aria-describedby={error ? `${inputId}-error` : hint ? `${inputId}-hint` : undefined} {...props} />
                {error && <p id={`${inputId}-error`} role="alert">{error}</p>}
            </div>
        );
    }
);
FormField.displayName = "FormField";
```

## Skip Links

```typescript
// components/SkipLinks.tsx
export function SkipLinks() {
    return (
        <div className="skip-links">
            <a href="#main-content" className="skip-link">Skip to main content</a>
            <a href="#navigation" className="skip-link">Skip to navigation</a>
        </div>
    );
}
```

## Live Announcer Hook

```typescript
// hooks/useAnnouncer.ts
import { useCallback, useRef, useEffect } from "react";

export function useAnnouncer() {
    const announcerRef = useRef<HTMLDivElement | null>(null);

    useEffect(() => {
        const announcer = document.createElement("div");
        announcer.setAttribute("role", "status");
        announcer.setAttribute("aria-live", "polite");
        announcer.className = "sr-only";
        document.body.appendChild(announcer);
        announcerRef.current = announcer;
        return () => { announcer.remove(); };
    }, []);

    const announce = useCallback((message: string, priority: "polite" | "assertive" = "polite") => {
        if (!announcerRef.current) return;
        announcerRef.current.setAttribute("aria-live", priority);
        announcerRef.current.textContent = "";
        setTimeout(() => { announcerRef.current!.textContent = message; }, 100);
    }, []);

    return announce;
}
```

## Best Practices

1. **Semantic HTML**: Use proper elements (button, nav, main)
2. **Focus Management**: Ensure logical focus order
3. **Color Contrast**: Maintain 4.5:1 contrast ratio
4. **Screen Readers**: Test with NVDA, VoiceOver
5. **Keyboard Navigation**: All elements keyboard accessible

When to Use This Prompt

This accessibility prompt is ideal for developers working on:

  • accessibility applications requiring modern best practices and optimal performance
  • Projects that need production-ready accessibility code with proper error handling
  • Teams looking to standardize their accessibility development workflow
  • Developers wanting to learn industry-standard accessibility patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their accessibility implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the accessibility code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this accessibility prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For accessibility projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...