Skill站外收录 @skilllib/skill-2117939930272414325
accessibility
确保前端界面全面符合 WCAG 2.2 AA 标准,通过语义化 HTML 结构、键盘可操作性、焦点管理、屏幕阅读器兼容支持、表单无障碍交互及高对比度视觉设计,覆盖从导航、内容组织到动态更新的完整用户路径。
商业与营销 AI 技能
Skills.MD
# Accessibility (WCAG 2.2 AA)
## Core Principles
- Semantic HTML elements and ARIA landmarks
- Keyboard-first navigation with visible focus states
- Skip links for main content in layouts
- Inclusive, people-first language
## Semantic HTML
```svelte
<!-- Use semantic elements -->
<header>
<nav aria-label="Main navigation">
<a href="/dashboard">Dashboard</a>
<a href="/projects">Projects</a>
</nav>
</header>
<main id="main-content">
<h1>Page Title</h1>
<section aria-labelledby="section-heading">
<h2 id="section-heading">Section Title</h2>
<article>...</article>
</section>
</main>
<footer>...</footer>
```
## Skip Links
```svelte
<!-- At top of layout -->
<a href="#main-content" class="sr-only focus:not-sr-only focus:absolute ...">
Skip to main content
</a>
```
## Form Accessibility
### Label Every Control
```svelte
<!-- Visible label -->
<label for="email">Email address</label>
<input id="email" type="email" />
<!-- Or using aria-label for icon-only inputs -->
<input type="search" aria-label="Search events" />
```
### Required Fields
```svelte
<label for="name">Name <span aria-hidden="true">*</span></label>
<input id="name" required aria-required="true" />
```
### Error Messages
```svelte
<input
id="email"
aria-invalid={hasError}
aria-describedby={hasError ? 'email-error' : undefined}
/>
{#if hasError}
<p id="email-error" class="text-destructive">
Please enter a valid email address
</p>
{/if}
```
### Validation Behavior
- On validation failure: focus first invalid input
- Never disable submit just to block validation
- Show inline errors linked via `aria-describedby`
## Keyboard Navigation
### Focus Order
```svelte
<!-- Natural tab order follows DOM order -->
<button>First</button>
<button>Second</button>
<button>Third</button>
<!-- Remove from tab order when hidden -->
<div hidden>
<button tabindex="-1">Hidden button</button>
</div>
```
### Focus Management in Dialogs
```typescript
// When dialog opens, focus first interactive element
$effect(() => {
if (open) {
dialogRef?.querySelector('input, button')?.focus();
}
});
// When dialog closes, return focus to trigger
const triggerRef = document.activeElement;
// ... on close
triggerRef?.focus();
```
### Keyboard Shortcuts
```svelte
<button
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handleClick();
}
}}
>
Action
</button>
```
## Images and Icons
### Informative Images
```svelte
<img src={user.avatar} alt={`Profile photo of ${user.name}`} />
```
### Decorative Images
```svelte
<img src="/decorative-pattern.svg" alt="" aria-hidden="true" />
```
### Icon Buttons
```svelte
<button aria-label="Delete event">
<TrashIcon aria-hidden="true" />
</button>
```
### Icons with Text
```svelte
<button>
<PlusIcon aria-hidden="true" />
Add Event
</button>
```
## ARIA Patterns
### Live Regions
```svelte
<!-- For dynamic updates (notifications, loading states) -->
<div aria-live="polite" aria-atomic="true">
{#if loading}
Loading events...
{/if}
</div>
<!-- For urgent messages -->
<div role="alert">
Error: Failed to save changes
</div>
```
### Expandable Content
```svelte
<button
aria-expanded={isExpanded}
aria-controls="panel-content"
>
{isExpanded ? 'Collapse' : 'Expand'}
</button>
<div id="panel-content" hidden={!isExpanded}>
Panel content
</div>
```
### Tabs
```svelte
<div role="tablist" aria-label="Event tabs">
<button role="tab" aria-selected={activeTab === 'details'}>
Details
</button>
<button role="tab" aria-selected={activeTab === 'stack'}>
Stack Trace
</button>
</div>
<div role="tabpanel" aria-labelledby="details-tab">
Tab content
</div>
```
## Color and Contrast
- Minimum contrast ratio: 4.5:1 for normal text
- 3:1 for large text and UI components
- Don't rely on color alone to convey information
```svelte
<!-- ✅ Good: Icon + color + text -->
<span class="text-destructive">
<AlertIcon aria-hidden="true" />
Error: Invalid input
</span>
<!-- ❌ Bad: Color only -->
<span class="text-destructive">Invalid input</span>
```
## Testing Accessibility
```bash
# Run axe-playwright audits in E2E tests
npm run test:e2e
```
```typescript
// In Playwright tests
import AxeBuilder from '@axe-core/playwright';
test('page is accessible', async ({ page }) => {
await page.goto('/dashboard');
const results = await new AxeBuilder({ page }).analyze();
expect(results.violations).toEqual([]);
});
```
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「accessibility」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次