Overview
This prompt aims to guide developers in creating accessible React components that comply with accessibility standards. It benefits programmers and organizations focused on inclusivity and usability for people with disabilities.
Prompt Overview
Purpose: Enhancing React components for accessibility ensures usability for people with disabilities.
Audience: This guide is intended for developers looking to improve the accessibility of their React applications.
Distinctive Feature: Incorporating ARIA roles, labels, and keyboard navigation enhances interaction for users relying on assistive technologies.
Outcome: By following these steps, developers can create more inclusive web applications that comply with accessibility standards.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Development Tools & DevOps, Productivity & Workflow
- Techniques: Role/Persona Prompting, Structured Output, Style Guide Adherence
- Models: Claude 3.5 Sonnet, Gemini 2.0 Flash, GPT-4o, Llama 3.1 70B
- Estimated time: 15-30 minutes
- Skill level: Advanced
Variables to Fill
- [text, onClick] – Text, Onclick
- [onClick] – Onclick
- [text] – Text
- [title, content, onClose] – Title, Content, Onclose
- [title] – Title
- [content] – Content
- [onClose] – Onclose
Example Variables Block
- [onClick]: handleClick
- [text]: Click me
- [title]: Modal Title
- [content]: This is the modal content.
- [onClose]: handleClose
The Prompt
Generate accessible code snippets for React components by incorporating best practices to ensure compliance with accessibility standards, such as WAI-ARIA. Your goal is to enhance React components for usability by people with disabilities, including adding appropriate ARIA roles, labels, and keyboard navigation.
# Steps
1. Identify Component Type:
– Determine the nature of the React component (e.g., button, form, modal) to apply suitable accessibility enhancements.
2. Use Semantic HTML:
– Prefer semantic HTML elements that naturally convey meaning and support accessibility (e.g., “, “, “).
3. Add ARIA Roles:
– Where necessary, add ARIA roles to non-semantic elements to communicate their role in the interface.
4. Ensure Keyboard Accessibility:
– Ensure the component is fully usable via keyboard interactions, such as adding `tabIndex` or handling keyboard events.
5. Provide ARIA Attributes:
– Use ARIA attributes like `aria-label`, `aria-labelledby`, `aria-describedby`, etc., to enhance clarity and support assistive technologies.
6. Test with Screen Readers:
– Test the component’s description and interaction with various screen readers to ensure information is conveyed effectively.
7. Incorporate Live Regions:
– Include appropriate ARIA live regions for dynamic content updates when necessary.
8. Follow WCAG Guidelines:
– Reference WCAG (Web Content Accessibility Guidelines) to ensure compliance with broader accessibility principles.
# Output Format
– Provide the updated React component with explanatory comments about each accessibility feature added.
– The code should be formatted in markdown as a JavaScript code block.
# Examples
### Example 1: Button Component
“`jsx
// This is a simple button component with accessibility features
function AccessibleButton([text, onClick]) {
return (
[text]
)
;}
“`
### Example 2: Modal Component
“`jsx
// Modal with ARIA attributes for accessibility
function AccessibleModal([title, content, onClose]) {
return (
# [title]
[content]
Close
)
;}
“`
# Notes
– Consider edge cases, such as dynamic content updates needing additional ARIA attributes.
– Use library solutions when custom components don’t provide necessary accessibility out-of-the-box.
Screenshot Examples
How to Use This Prompt
- [COMPONENT_TYPE]: Type of React component being enhanced.
- [SEMANTIC_HTML]: Use of meaningful HTML elements.
- [ARIA_ROLES]: Roles added to non-semantic elements.
- [KEYBOARD_ACCESSIBILITY]: Support for keyboard navigation.
- [ARIA_ATTRIBUTES]: Additional attributes for clarity.
- [SCREEN_READER_TESTING]: Testing with various screen readers.
- [LIVE_REGIONS]: ARIA live regions for dynamic updates.
- [WCAG_GUIDELINES]: Compliance with accessibility standards.
Tips for Best Results
- Identify Component Type: Determine the component type to apply relevant accessibility enhancements.
- Use Semantic HTML: Prefer semantic elements like
<button>and<form>for better accessibility. - Add ARIA Roles: Use ARIA roles on non-semantic elements to clarify their purpose in the UI.
- Ensure Keyboard Accessibility: Make components fully navigable via keyboard, handling events and using
tabIndexas needed.
FAQ
- What is the purpose of ARIA roles in React components?
ARIA roles help communicate the purpose of non-semantic elements to assistive technologies, enhancing accessibility. - How can you ensure keyboard accessibility in React?
Add `tabIndex` to elements and handle keyboard events to allow navigation and interaction via keyboard. - Why use semantic HTML in React components?
Semantic HTML naturally conveys meaning, improving accessibility and usability for all users, including those with disabilities. - What are ARIA live regions?
ARIA live regions notify assistive technologies about dynamic content updates, ensuring users are informed of changes.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


