Visually Hidden

v0.0.10

v0.0.10StableHeadlessStatelessAccessibleApache-2.0
Installation mix mishka.ui.gen.headless visually_hidden
Source View Source

Overview of the Phoenix and LiveView Headless Visually Hidden Component

The Mishka Chelekom Headless Visually Hidden component hides content from sight and keeps it available to screen readers in Phoenix and LiveView. It renders a span with the standard visually-hidden styles applied inline: absolute position, a 1px box, clipped, no wrapping. Because the styles are inline, it works with no stylesheet at all.

Use it for text that explains an icon or a symbol, for extra context in a link, or for text a live region announces. It takes class and any global attribute, such as id or aria-live. The root also carries the chelekom-visually-hidden class.

Base UI Visually Hidden example - a button with a hidden label (Phoenix headless)

Base UI Visually Hidden example - a button with a hidden label (Phoenix headless)

heex
<.button
  type="button"
  class="relative rounded-md border border-neutral-300 px-3 py-1.5 text-sm text-neutral-800 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800"
>
  ★
  <.visually_hidden>Add to favorites</.visually_hidden>
</.button>

Other uses

Add context to a link whose visible text is the same on every row.

heex
<a href={"/posts/#{post.id}"}>
  Read more
  <.visually_hidden>about {post.title}</.visually_hidden>
</a>

Or hold the text of a live region, so a status change is announced without changing the layout.

heex
<.visually_hidden aria-live="polite">{@status}</.visually_hidden>

Parts & data attributes

There are no inner parts and no state attributes. The root is a single span around the slot content.

Accessibility

Hidden text stays in the accessibility tree, so screen readers read it in place. Put it inside the control it describes, and it becomes part of that control's accessible name. Do not use it for content that sighted keyboard users also need, because it cannot be revealed on focus.