# VisuallyHidden

Crate: `libero`
Import: `use libero::components::VisuallyHidden;`
Feature: `visually-hidden` (on by default, turns on `box`; [features.md](features.md))
Source: <https://github.com/tdymel/libero/tree/main/libero/src/components/accessibility/visually_hidden.rs>
Index: [index.md](index.md) lists every other page
Description: A `span` read by screen readers but hidden from sighted layout, for extra context on something vague on its own.

Content for screen readers only, such as extra context for a link that is
vague on its own. With `focusable` on it is a skip link. To hide a
component's own element or one of its parts the same way, pass
`visually_hidden_sx()` to its `sx` or a `parts` entry.

## Usage

Sighted users see "Read more", and a screen reader reads "Read more about
focus management".

```rust
use dioxus::prelude::*;
use libero::components::{Anchor, Text, VisuallyHidden};

#[component]
fn Demo() -> Element {
    rsx! {
        Text {
            Anchor {
                to: "https://example.com",
                "Read more"
                VisuallyHidden { " about focus management" }
            }
        }
    }
}
```

## Props

| Prop | Type | Default | Description |
|---|---|---|---|
| `focusable` | `bool` | `false` | Shows the content while focus is inside it, for a skip link. |
| `children` | `Element` | required | The screen-reader-only content. |

Like every component, `VisuallyHidden` also takes the shared props `sx`, `class`,
`states`, `hidden_from`, `visible_from`, and any extra HTML attributes.

## Accessibility

### Libero handles

- With `focusable`, the content shows while focus is inside it, above a sticky
  `Header` and below modals and popovers.

### You must

- Place the text where it should be read, inside the link and not next to it.
- Use it for text a screen reader user is missing, never to hide something
  sighted users need. To replace a control's whole name, use `aria_label`
  instead.
- Keep the children to text unless `focusable` is set, or keyboard focus lands
  somewhere invisible.
- A skip link shows at its place in the flow, so put it first on the page.
  Further down, put it in a positioned parent and set `position: absolute`
  through `sx`, or Tab never scrolls it into view.

The link needs a target with that id; `tabindex: "-1"` lets it take the focus:

```rust
use dioxus::prelude::*;
use libero::components::{Anchor, VisuallyHidden};

#[component]
fn Demo() -> Element {
    rsx! {
        VisuallyHidden {
            focusable: true,
            Anchor { to: "#main", "Skip to content" }
        }
        main { id: "main", tabindex: "-1", "The page" }
    }
}
```

### Example

A "Read more" link in a news card with `VisuallyHidden { " about the launch"
}` inside it: sighted users see "Read more", and a screen reader reads "Read
more about the launch".

## Theme defaults

None. The hiding rules are fixed.

## CSS variables

None.

## Data attributes

None.
