Framework Accessibility

Framework-specific accessibility patterns and fix templates for React, Vue, Angular, Svelte, Next.js, and Tailwind CSS.

Published by @Community-Access·0 agent reads / 30d·0 saves·

Framework-Specific Accessibility Patterns

React / Next.js

Common Pitfalls

PatternIssueFix
onClick on <div>Not keyboard accessibleUse <button> or add role="button", tabIndex={0}, onKeyDown
dangerouslySetInnerHTMLMay inject inaccessible contentAudit injected HTML for ARIA, headings, alt text
React.Fragment as rootMay break landmark treeEnsure fragments don't interrupt landmark nesting
Missing key on listsCan cause focus loss on re-renderUse stable keys (not array index) for interactive lists
Portal without focus trapFocus can escape to backgroundWrap portal content in FocusTrap component
useEffect focus managementFocus may not fire on mountUse useRef + useEffect with proper dependency array

Fix Templates

// Bad: div as button
<div onClick={handleClick}>Submit</div>

// Good: semantic button
<button onClick={handleClick}>Submit</button>

// Bad: image without alt in Next.js
<Image src="/hero.jpg" width={800} height={400} />

// Good: image with alt
<Image src="/hero.jpg" width={800} height={400} alt="Team collaborating in a modern office" />

// Bad: no focus management on route change
useEffect(() => {
  // nothing
}, [location]);

// Good: focus management on route change
useEffect(() => {
  const mainContent = document.getElementById('main-content');
  if (mainContent) {
    mainContent.focus();
    mainContent.scrollIntoView();
  }
}, [location]);

// Bad: link opening new tab
<a href={url} target="_blank">Resource</a>

// Good: link with new tab warning
<a href={url} target="_blank" rel="noopener noreferrer">
  Resource <span className="sr-only">(opens in new tab)</span>
</a>

Vue

Common Pitfalls

PatternIssueFix
v-html with user contentMay inject inaccessible markupSanitize and audit injected HTML
v-if on live regionsRemoves element from DOM, breaks announcementsUse v-show for live regions instead
<transition> without focusFocus lost when content transitionsManage focus in @after-enter hook
<teleport> to bodyContent outside app landmark treeAdd landmark roles to teleported content

Fix Templates

<!-- Bad: v-if on live region -->
<div v-if="message" aria-live="polite">{{ message }}</div>

<!-- Good: v-show keeps element in DOM -->
<div v-show="message" aria-live="polite">{{ message }}</div>

<!-- Bad: no focus after transition -->
<transition name="fade">
  <div v-if="showModal" class="modal">...</div>
</transition>

<!-- Good: focus managed after transition -->
<transition name="fade" @after-enter="focusModal">
  <div v-if="showModal" ref="modal" class="modal" tabindex="-1">...</div>
</transition>

Angular

Common Pitfalls

PatternIssueFix
[aria-label] bindingInvalid - ARIA is not a propertyUse [attr.aria-label]
*ngFor without trackByFocus loss on list re-renderAdd trackBy function
No LiveAnnouncerRoute changes not announcedInject LiveAnnouncer and announce navigation
OnPush + live regionsChange detection may not triggerUse ChangeDetectorRef.markForCheck()

Fix Templates

// Bad: ARIA binding
<button [aria-label]="label">X</button>

// Good: ARIA attribute binding
<button [attr.aria-label]="label">X</button>

// Bad: ngFor without trackBy
<li *ngFor="let item of items">{{ item.name }}</li>

// Good: ngFor with trackBy
<li *ngFor="let item of items; trackBy: trackById">{{ item.name }}</li>

// Route change announcements
constructor(private liveAnnouncer: LiveAnnouncer, private router: Router) {
  this.router.events.pipe(
    filter(event => event instanceof NavigationEnd)
  ).subscribe((event: NavigationEnd) => {
    this.liveAnnouncer.announce(`Navigated to ${this.getPageTitle()}`);
  });
}

Svelte

Common Pitfalls

PatternIssueFix
{#if} without focus managementFocus lost when content appearsUse use:action to focus new content
transition: without motion checkAnimations play regardless of user preferenceAdd prefers-reduced-motion check
on:click on non-interactiveNot keyboard accessibleUse <button> or add keyboard handlers

Fix Templates

<!-- Bad: click on div -->
<div on:click={toggle}>Toggle</div>

<!-- Good: keyboard accessible -->
<button on:click={toggle}>Toggle</button>

<!-- Bad: animation without motion preference -->
<div transition:fly={{ y: 200 }}>Content</div>

<!-- Good: respects motion preference -->
<div transition:fly={{ y: reducedMotion ? 0 : 200, duration: reducedMotion ? 0 : 300 }}>Content</div>

<script>
  const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
</script>

Tailwind CSS

Common Pitfalls

PatternIssueFix
outline-noneRemoves focus indicatorPair with ring-2 ring-offset-2 focus-visible:ring-blue-500
text-gray-400 on bg-whiteFails 4.5:1 contrastUse text-gray-600 or darker
No motion-reduce: variantAnimations ignore user preferenceAdd motion-reduce:transition-none
Missing focus: stylesNo visible focus indicatorAdd focus:ring-2 focus:ring-blue-500
sr-only missingScreen reader text not availableAdd <span class="sr-only">description</span>

Contrast-Safe Tailwind Pairs

BackgroundMinimum TextRatio
bg-whitetext-gray-6004.55:1
bg-whitetext-gray-7006.62:1
bg-gray-50text-gray-7006.29:1
bg-gray-900text-gray-3005.92:1
bg-blue-600text-white5.23:1
bg-red-600text-white4.54:1
bg-green-700text-white4.58:1

Fix Templates

<!-- Bad: no focus indicator -->
<button class="bg-blue-500 text-white px-4 py-2 rounded outline-none">
  Submit
</button>

<!-- Good: visible focus indicator -->
<button class="bg-blue-500 text-white px-4 py-2 rounded focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2">
  Submit
</button>

<!-- Bad: low contrast -->
<p class="text-gray-400">Important information</p>

<!-- Good: adequate contrast -->
<p class="text-gray-700">Important information</p>

<!-- Bad: animation without motion preference -->
<div class="transition-transform duration-300 hover:scale-105">Card</div>

<!-- Good: respects motion preference -->
<div class="transition-transform duration-300 hover:scale-105 motion-reduce:transition-none motion-reduce:hover:scale-100">Card</div>

More on the bench

SKILL0

User Research Synthesizer

Synthesize user research findings from interviews, surveys, and analytics. Create insight reports, customer journey maps, and actionable recommendations based on research data and qualitative findings.

product-management+2
0
SKILL0

Frontend Design

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

ux-product-design+2
0
SKILL0

Playwright Skill

Complete browser automation with Playwright. Auto-detects dev servers, writes clean test scripts to /tmp. Test pages, fill forms, take screenshots, check responsive design, validate UX, test login flows, check links, automate any browser task. Use when user wants to test websites, automate browser interactions, validate web functionality, or perform any browser-based testing.

software-engineering+2
0