视觉隐藏
对齐目标:@astryxdesign/core v0.7.1 · VisuallyHidden
What you see
What a screen reader hears
Download, button Share, button Delete, button
Actions available: Download, Share, Delete.
使用方法 #
从独立入口导入 VisuallyHidden。默认插槽为必需项:
Vue
<script setup lang="ts">
import { VisuallyHidden } from '@astryx-vue/core/VisuallyHidden'
</script>
<template>
<a href="/articles/accessibility">
了解更多
<VisuallyHidden>关于无障碍基础组件</VisuallyHidden>
</a>
</template>最佳实践 #
| 指引 | 实践 |
|---|---|
| 推荐 | 用于为纯图标按钮和控件提供屏幕阅读器可播报的无障碍名称。 |
| 推荐 | 以块级元素(as="div")渲染,并设置 aria-live,用于播报拖放或结果数量等动态更新。 |
| 避免 | 用它对所有人隐藏内容。内容仍保留在无障碍树中。如需完全移除,应使用条件渲染或 hidden。 |
| 避免 | 在其中放置交互控件。内容不可见,也无法接收指针输入。 |
示例 #
视觉隐藏 — 实时播报
Drag-and-drop and other visual-only changes are silent to screen readers. A live region narrates them.
Task is in Backlog
Task moved to Backlog
任务被移到下一列时,aria-live 把新位置读出来。看见箭头的人不用听这段话。
视觉隐藏 — 结构标题
The layout makes this group obvious to sighted users. A hidden heading gives screen-reader users the same landmark to jump to.
Build status
astryx-corePassing
astryx-chartsFailing
astryx-cliPassing
这一组在视觉上已经成块,但没有可见标题。隐藏的 h2 让屏幕阅读器能跳到这里。
视觉隐藏 — 补充上下文
Revenue$48.2k
+12% increase from last month
Churn2.1%
-4% decrease from last month
箭头只是装饰。涨了还是跌了,写在 VisuallyHidden 里给屏幕阅读器。