DisplayReact
Text that a screen reader reads and the page does not show.
Rendered by React 19.3.1
Not measured yetTests passing in React
2.4 KiBSize
Not measured yetMemory
Not measured yetSpeed
[N] commits
Installation
npm i @hamur/reactNot on npm yet. The package goes out under the chosen name.
Anatomy
Import the component and assemble its parts:
<VisuallyHidden />Examples
Caption
A table whose caption, "Invoices, newest first", only screen readers get.
Label
A search input inside a label whose only text is hidden.
API reference
0 props across 1 parts, in React syntax. className, style, render are listed once, under Shared props.
VisuallyHiddenVisuallyHidden
Content that is not painted and takes no room in the layout, and stays in the accessibility tree. Renders a <span>.
Shared props
Every part that renders an element takes these.
| Prop | Type |
|---|---|
classNameCSS class applied to the element, or a function that
returns a class based on the component's state. | string | ((state: State) => string | undefined) |
styleStyle applied to the element, or a function that
returns a style object based on the component's state. | React.CSSProperties | ((state: State) => React.CSSProperties | undefined) |
renderAllows you to replace the component's HTML element
with a different tag, or compose it with another component. | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, State> |
Keyboard and accessibility
Keyboard
VisuallyHidden takes no focus and has no keys.
Accessibility
| Part | Sets | So that |
|---|---|---|
| VisuallyHidden | no role and no ARIA; the clipped, absolute style | its text names the control, label or caption around it and no sighted user sees it |
Focus order
- VisuallyHidden is not focusable; focus passes over it.
- A focusable control inside it is kept hidden when it takes focus, which fails WCAG 2.4.7 and 2.4.11; the one exception is a native control behind a visible stand-in that shows the focus.