Skip to content

Early previewhamur is not on npm yet. The components are being built in the open, follow along on GitHub.

DisplayReact

Visually Hidden

Text that a screen reader reads and the page does not show.

Rendered by React 19.3.1

import { VisuallyHidden } from '@hamur/react/visually-hidden'

export default function VisuallyHiddenExample() {
  return (
    <div className="stack vh-frame">
      <div className="vh-row">
        <button type="button" className="icon-button">
          <svg className="vh-icon" viewBox="0 0 16 16" aria-hidden="true">
            <circle cx="7" cy="7" r="4.5" />
            <path d="M10.5 10.5L14 14" />
          </svg>
          <VisuallyHidden>Search</VisuallyHidden>
        </button>
        <button type="button" className="icon-button">
          <svg className="vh-icon" viewBox="0 0 16 16" aria-hidden="true">
            <path d="M2 5h12M2 11h12" />
            <circle cx="5" cy="5" r="1.6" />
            <circle cx="11" cy="11" r="1.6" />
          </svg>
          <VisuallyHidden>Settings</VisuallyHidden>
        </button>
        <button type="button" className="icon-button">
          <svg className="vh-icon" viewBox="0 0 16 16" aria-hidden="true">
            <path d="M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5" />
          </svg>
          <VisuallyHidden>Delete</VisuallyHidden>
        </button>
      </div>
      <p className="muted">Each button shows an icon; a screen reader reads its hidden name.</p>
    </div>
  )
}
Not measured yetTests passing in React
2.4 KiBSize
Not measured yetMemory
Not measured yetSpeed
[N] commits

Installation

npm i @hamur/react

Not 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.

VisuallyHiddenCaption.tsx
import { VisuallyHidden } from '@hamur/react/visually-hidden'

const invoices = [
  { id: 'INV-1042', client: 'Northwind', amount: '$1,200.00' },
  { id: 'INV-1041', client: 'Contoso', amount: '$860.00' },
  { id: 'INV-1040', client: 'Fabrikam', amount: '$2,430.00' },
]

export default function VisuallyHiddenCaptionExample() {
  return (
    <div className="stack vh-frame">
      <table className="vh-table">
        <caption>
          <VisuallyHidden>Invoices, newest first</VisuallyHidden>
        </caption>
        <thead>
          <tr>
            <th scope="col">Invoice</th>
            <th scope="col">Client</th>
            <th scope="col">Amount</th>
          </tr>
        </thead>
        <tbody>
          {invoices.map((invoice) => (
            <tr key={invoice.id}>
              <td>{invoice.id}</td>
              <td>{invoice.client}</td>
              <td>{invoice.amount}</td>
            </tr>
          ))}
        </tbody>
      </table>
    </div>
  )
}

Label

A search input inside a label whose only text is hidden.

VisuallyHiddenLabel.tsx
import { VisuallyHidden } from '@hamur/react/visually-hidden'

export default function VisuallyHiddenLabelExample() {
  return (
    <div className="stack vh-frame">
      <label>
        <VisuallyHidden>Search invoices</VisuallyHidden>
        <input className="input" type="search" placeholder="Search invoices" />
      </label>
    </div>
  )
}

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.

Shared props
PropType
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

What the parts set
PartSetsSo that
VisuallyHiddenno role and no ARIA; the clipped, absolute styleits text names the control, label or caption around it and no sighted user sees it

Focus order

  1. VisuallyHidden is not focusable; focus passes over it.
  2. 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.