# Message actions

Reply and React beside a message, over it in a narrow window and under it on a phone, on focus and in its menu.

Live variants: https://design.arcadia.is/components/message-actions

```tsx
import { MessageActions, MessageActionItems } from "@arcadia/ui";
```

```tsx
import { useState, useRef } from "react";
import { ReplyQuote } from "@arcadia/ui";

function MessageActionsConversation() {
  const [said, setSaid] = useState<readonly Said[]>(FIRST);
  const [replying, setReplying] = useState<Said | null>(null);
  const [held, setHeld] = useState<string | null>(null);
  const composer = useRef<HTMLDivElement>(null);
  const reply = (m: Said) => {
    setReplying(m);
    requestAnimationFrame(() => composer.current?.querySelector("textarea")?.focus());
  };
  const jump = (id: string) => {
    const el = document.getElementById(id);
    el?.scrollIntoView({ block: "nearest" });
    el?.focus({ preventScroll: true });
    setHeld(id);
  };
  const send = (text: string) => {
    setSaid((now) => [...now, { id: `m${now.length + 1}`, side: "end", author: NORA, text, replyTo: replying?.id }]);
    setReplying(null);
  };
  return (
    <div {...sx("cmp-message-actions-stream", MessageActionsStyles.stream)}>
      {said.map((m) => (
        <MessageActionsMessage key={m.id} said={m} quoted={said.find((q) => q.id === m.replyTo)} flash={held === m.id}
          onReply={() => reply(m)} onJump={jump} onFlashEnd={() => setHeld(null)} />
      ))}
      <div ref={composer} onKeyDown={(e) => { if (e.key === "Escape" && replying) { e.preventDefault(); setReplying(null); } }}>
        <MessageActionsComposerFrame placeholder="Write a reply" onSubmit={send}>
          {replying && <ReplyQuote placement="composer" author={replying.author} text={replying.text} onCancel={() => setReplying(null)} />}
        </MessageActionsComposerFrame>
      </div>
    </div>
  );
}
```

## Keyboard

- Tab: From the message to Reply, then React; each shows the two. With `touchActions="menu"` neither is a stop: the message's menu holds both.
- Enter + Space: On Reply, replies; on React, opens the picker with focus on its first cell.
- Esc: Closes the picker; focus goes back to React.
- Shift+F10: Opens the message's menu, which holds Reply and React.

## Placement & visibility

Actions stand beside the message bubble and vertically centered against its height: on the right (`inline-end`) of left-aligned `start` bubbles, and mirrored on the left (`inline-start`) of right-aligned `end` bubbles. On fine pointers they stay hidden at rest (`opacity: 0`, `pointer-events: none`) and appear only on hover, keyboard focus-within, or while a picker or menu is open. On narrow fine-pointer viewports they float over the bubble's top-inner edge so message lines stay unobstructed; on touch screens the seat falls back cleanly below the bubble (or into the context menu with `touchActions="menu"`).

## Accessibility

Reply and React are buttons named by `replyLabel` and `reactLabel`, each with its tooltip; React says it opens a dialog and whether it is open. The picker is that dialog, named the same. The actions sit in the reading order of the row: after a message at `start`, before one at `end`. On a touch screen the seat stands on a line of its own under the message, where the message comes first at `start` and the seat first at `end`.

## API reference

### MessageActions

- `side` (`"start" | "end"`, default `"start"`): Which side of the conversation a bubble or a group sits on: `start` is the other party, `end` is you.
- `extra` (`readonly ReactElement[]`)
- `interactionRow` (`(actions: HTMLElement) => HTMLElement | null`)
- `onReply` (`() => void`)
- `choices` (`readonly ReactionChoice<N>[]`, default `[]`)
- `given` (`Iterable<N>`)
- `onReact` (`(name: N) => void`)
- `reactOpen` (`boolean`)
- `onReactOpenChange` (`(open: boolean, details: OpenChangeDetails) => void`)
- `selected` (`boolean`, default `false`)
- `touchActions` (`"shown" | "menu"`, default `"shown"`)
- `replyLabel` (`string`, default `"Reply"`)
- `reactLabel` (`string`, default `"React"`)
- `replyProps` (`ButtonMarks`): The marks a caller may set on a kit button whose name the kit gives: its own `data-*` only.
- `reactProps` (`ButtonMarks`): The marks a caller may set on a kit button whose name the kit gives: its own `data-*` only.
- `columns` (`number`)
- `rootStyle` (`RootStyle<MessageActionsKnobs>`)

### MessageActionItems

- `onReply` (`() => void`, required)
- `onReact` (`() => void`)
- `replyLabel` (`string`, default `"Reply"`)
- `reactLabel` (`string`, default `"React"`)
