# Visually Hidden

## Usage

Import `VisuallyHidden` from its dedicated entry. The default slot is required:

```vue
<script setup lang="ts">
import { VisuallyHidden } from '@astryx-vue/core/VisuallyHidden'
</script>

<template>
  <a href="/articles/accessibility">
    Read more
    <VisuallyHidden> about accessibility primitives</VisuallyHidden>
  </a>
</template>
```

## Best practices

| Guidance | Practices |
| --- | --- |
| Do | Use to give icon-only buttons and controls an accessible name that screen readers announce. |
| Do | Render as a block element (as="div") with aria-live to announce dynamic updates like drag-and-drop or result counts. |
| Don't | Use it to hide content from everyone; it stays in the accessibility tree; use conditional rendering or `hidden` to remove content entirely. |
| Don't | Put interactive controls inside it; the content is not visible and cannot receive pointer input. |

## Examples

### Live region

When the task moves to the next column, aria-live reads the new place. People who can see the label do not need that sentence.

```vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { VisuallyHidden } from '@astryx-vue/core/VisuallyHidden'
import { computed, shallowRef } from 'vue'

const columns = ['Backlog', 'In progress', 'Done'] as const
const column = shallowRef(0)
const current = computed(() => columns[column.value])

function move(): void {
  column.value = (column.value + 1) % columns.length
}
</script>

<template>
  <VStack :gap="4" h-align="start">
    <Text type="supporting" color="secondary">
      Drag-and-drop and other visual-only changes are silent to screen readers. A live region narrates them.
    </Text>
    <HStack :gap="3" align="center">
      <Button label="Move task" variant="secondary" @click="move" />
      <Text type="body">
        Task is in <Text as="span" weight="bold">
          {{ current }}
        </Text>
      </Text>
    </HStack>
    <VisuallyHidden as="div" aria-live="polite">
      Task moved to {{ current }}
    </VisuallyHidden>
  </VStack>
</template>
```

### Structural heading

The group is obvious on screen and has no visible heading. A hidden h2 gives screen-reader users a landmark to jump to.

```vue
<script setup lang="ts">
import { Badge } from '@astryx-vue/core/Badge'
import { Card } from '@astryx-vue/core/Card'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { VisuallyHidden } from '@astryx-vue/core/VisuallyHidden'

const items = [
  { name: 'astryx-core', status: 'Passing', variant: 'success' },
  { name: 'astryx-charts', status: 'Failing', variant: 'error' },
  { name: 'astryx-cli', status: 'Passing', variant: 'success' },
] as const
</script>

<template>
  <VStack :gap="3" h-align="start">
    <Text type="supporting" color="secondary">
      The layout makes this group obvious to sighted users. A hidden heading gives screen-reader users the same landmark to jump to.
    </Text>
    <VisuallyHidden as="h2">
      Build status
    </VisuallyHidden>
    <VStack :gap="2">
      <Card v-for="item in items" :key="item.name" variant="muted" :padding="3">
        <HStack :gap="3" align="center">
          <Text type="body">
            {{ item.name }}
          </Text>
          <Badge :variant="item.variant">
            {{ item.status }}
          </Badge>
        </HStack>
      </Card>
    </VStack>
  </VStack>
</template>
```

### Supplementary context

The arrow is decoration. Whether the number went up or down is written in VisuallyHidden for a screen reader.

```vue
<script setup lang="ts">
import { Card } from '@astryx-vue/core/Card'
import { HStack, VStack } from '@astryx-vue/core/Stack'
import { Text } from '@astryx-vue/core/Text'
import { VisuallyHidden } from '@astryx-vue/core/VisuallyHidden'

const stats = [
  { label: 'Revenue', value: '$48.2k', delta: '+12%', direction: 'up' },
  { label: 'Churn', value: '2.1%', delta: '-4%', direction: 'down' },
] as const
</script>

<template>
  <HStack :gap="4" wrap="wrap">
    <Card v-for="item in stats" :key="item.label" variant="muted">
      <VStack :gap="1">
        <Text type="supporting" color="secondary">
          {{ item.label }}
        </Text>
        <Text type="display-3">
          {{ item.value }}
        </Text>
        <HStack :gap="1" align="center">
          <span
            class="css-icon css-icon--sm"
            :class="item.direction === 'up' ? 'i-carbon-arrow-up' : 'i-carbon-arrow-down'"
            aria-hidden="true"
          />
          <Text type="body">
            {{ item.delta }}
            <VisuallyHidden>
              {{ item.direction === 'up' ? ' increase' : ' decrease' }} from last month
            </VisuallyHidden>
          </Text>
        </HStack>
      </VStack>
    </Card>
  </HStack>
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `as` | `string \| Component` | `'span'` | Root HTML element or Vue component. Use `div` for a live region or block content. |

## Slots

| Name | Description |
| --- | --- |
| `default` | Content exposed to assistive technology while hidden visually. This slot is required. |

## Template ref

The component exposes `element` with type `HTMLElement | null`.
`element` points to the rendered root element.

## Styling constraints

- The component ignores incoming `class`.
- The component ignores incoming `style`.
- External styles cannot replace the fixed hiding rules.

## Native attributes

The root element receives:

- `aria-*` attributes.
- `role`.
- `id`.
- `data-*` attributes.
- Native event listeners.

:::warning Hidden content
Do not put interactive controls inside `VisuallyHidden`. The visual interface cannot show those controls.

To hide content from all users, use conditional rendering or the native `hidden` attribute.
:::
