# Fade text

Show a shorter form when space is tight. If it still does not fit, truncate with an ellipsis and offer the full text.

Live variants: https://design.arcadia.is/components/fade-text

```tsx
import { FadeText } from "@arcadia/ui";
```

```tsx
import { StatusDot, FadeText } from "@arcadia/ui";

function Sidebar() {
  const chats = [
    ["Fix the flaky upload test on the staging runner after the queue moved", "now"],
    ["Colour tokens", "2m"],
    ["Plan the onboarding flow for invited members", "4h"],
    ["Quarterly report", "2d"],
  ] as const;
  return (
    <nav {...sx("cmp-rows", cmp.rows, cmp.rowsNarrow)} aria-label="Chats">
      {chats.map(([title, when]) => (
        <span key={title} {...stylex.props(s.row)}>
          <StatusDot />
          <FadeText last={false}>{title}</FadeText>
          <span {...stylex.props(s.meta)}>{when}</span>
        </span>
      ))}
    </nav>
  );
}
```

## Accessibility

The full text is always in the page, so it is what a screen reader reads and what a copy takes, whatever the eye sees. When a shorter form shows, the full text stays in the DOM out of sight and the shown form is hidden from assistive technology, so nothing is read twice: a button whose label shows "Continue" is still named by its whole label.

On hover, and when the keyboard brings focus to the text or to the control that holds it (a tab, a row, a button), a tooltip shows the full text, but only while the text is cut or shortened, and it leaves with the focus. It stands below the text, above where there is no room below, and never beside it, where a neighbouring tab or chip would be covered; a list row's own text gets it beside the row. A press's focus adds none: its hover showed it already. Its content is hidden from assistive technology, since the text already says it. Pass `full={false}` where the row opens a hover card of its own. Text that does not fit ends with an ellipsis. The focus ring stays whole.

## API reference

### FadeText

- `forms` (`readonly (ReactNode | { cut: ReactNode })[]`): Shorter forms, longest first: the first that fits shows; a `{ cut }` form shows a shortened fragment. Default: an address's segments or a path's parts; prose fills its box (ARC-1000).
- `last` (`boolean`, default `true`): `false`: text follows on its row, so a shortened form ends on a content word.
- `lines` (`number`): Maximum lines before truncation.
- `full` (`"tooltip" | false`, default `"tooltip"`): `tooltip`: the full text while cut or shortened, on hover and on keyboard focus of the text or of the control that holds it, leaving with the focus; below the text, above where there is no room below, never over a neighbour beside it (a list row's own text, beside the row). `false` beside a hover card.
- `onForm` (`(form: number) => void`): Told the form it shows (0: the whole text).
- `rootStyle` (`FadeTextStyle`)
- `children` (`ReactNode`, required): The full text, always the accessible name.

Rest props go to `<span>` props.
