Visually hidden
Slant / Primitives
Text for screen readers only: hidden from sight, not from assistive technology.
Demo
Usage
import { Button, TrashIcon, VisuallyHidden } from '@tuttn/slant'
// The hidden text names the button; the icon is aria-hidden.
<Button icon><TrashIcon /><VisuallyHidden>Delete checkpoint</VisuallyHidden></Button>
// Extra words where the visible ones lean on what's around them.
<Button size="sm">Retry<VisuallyHidden> handoff.md</VisuallyHidden></Button>
// as picks the element: a legend for a fieldset, a caption for a table.
<fieldset>
<VisuallyHidden as="legend">Choose a plan</VisuallyHidden>
…
</fieldset>Props
| Prop | Type | Default | Description |
|---|---|---|---|
as | 'span' | 'p' | 'legend' | 'label' | 'caption' | 'div' | 'span' | The element to render: a legend for a fieldset, a caption for a table, a label for a control. |
…rest | HTMLAttributes | — | className, style, id and every other attribute go on the element, and a ref reaches it. With an id, a control can point at it through aria-labelledby or aria-describedby. |
Accessibility
- Hidden from sight only. The
sl-srclass clips it to a 1px box, so screen readers still read it;display: noneorhiddenwould hide it from everyone. - It stays hidden when focused, so keep links and buttons out of it: a keyboard user would land on something they can't see.
- Start an addition with a space or a comma (
<VisuallyHidden>, done</VisuallyHidden>) so the words don't run together. Stepper does exactly this. - Prefer visible text when there is room. Hidden text suits icon-only buttons and repeated actions, such as Retry or Remove, that need the item's name.