VisuallyHidden
VisuallyHidden.Root hides its content on screen and keeps it for assistive technology. It is a span, so it fits inside a button or a line of text. With focusable, it shows its content again while focus is inside, for skip links.
On this page
import { Text } from '@tounsoo/todae/text';
import { VisuallyHidden } from '@tounsoo/todae/visually-hidden';
export default function VisuallyHiddenLabel() {
return (
<Text.Root>
3 <VisuallyHidden.Root>unread messages</VisuallyHidden.Root>
<span aria-hidden="true"> ✉</span>
</Text.Root>
);
}
3 unread messages
Server Components can import it from @tounsoo/todae/visually-hidden. The declarations use !important, so a class or style you add never shows the hidden content. Prefer aria-label when the element already takes one, such as an icon-only Button.Root.
Accessible composition
Todae handles: Hiding. VisuallyHidden.Root clips itself to 1px and leaves the layout, but stays in the accessibility tree, so its text still counts, for example toward a button's name. With focusable it does the same until focus is on it or inside it (:focus-within), then shows. It sets no role, ARIA attribute or tabindex.
You supply: The hidden text itself, in the page's language. For a skip link, the target: href="#main" needs an element with id="main".
Watch for: A link, button or other focusable element inside VisuallyHidden.Root without focusable: it stays in the Tab order with nothing on screen, so focus seems to vanish. Hidden text that repeats visible text in the same name, which is then read twice. Hidden text inside an element that also has aria-label: aria-label wins, and the hidden text is not part of the name.
When to use
When: Text a screen reader needs that sighted users get from context: an icon's meaning, the unit after a number, a skip link.
When not: Content no one should reach → hidden. A control's name when it takes aria-label → aria-label. Hiding from assistive technology only → aria-hidden.
Props
| Name | Type | Description |
|---|---|---|
focusable | boolean | Shows the content again while focus is on it or inside it, for a skip link. Default: false |
children | React.ReactNode | Text for assistive technology, or a focusable element such as a skip link. |