# Ask

An ask where it was posted: under the question's words, its choices, its otherwise line, and how it ended.

Live variants: https://design.arcadia.is/components/ask

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

Pick a choice or use Other to write your own. Otherwise tells you what happens if you don’t answer.

```tsx
import { useState } from "react";
import { fmtTime, MessageGroup, Bubble, FormattedText, Ask } from "@arcadia/ui";

function Asked() {
  const [state, setState] = useState<AskState>("open");
  const [answer, setAnswer] = useState<{ text: string; at: string }>();
  const reply = async (r: AskReply) => {
    await wait(600);
    setAnswer({ text: "choice" in r ? r.choice : "choices" in r ? r.choices.join(", ") : "words" in r ? r.words : r.offer, at: fmtTime(Date.now()) });
    setState("answered");
  };
  return (
    <MessageGroup author={scout}>
      <Bubble>
        <FormattedText source={QUESTION} />
        <Ask you choices={CHOICES} other otherwise={OTHERWISE} askedOf="Ada Lovelace" state={state} answer={answer} onAnswer={reply}
          rootStyle={styles.under} />
      </Bubble>
    </MessageGroup>
  );
}
```

```tsx
import { useState } from "react";
import { fmtTime, Ask } from "@arcadia/ui";

function ReleaseWindow() {
  const [answer, setAnswer] = useState<{ text: string; at: string }>();
  const summary = [
    { id: "tonight", label: "Ship tonight", summary: "Release at 18:00 with overnight support." },
    { id: "morning", label: "Ship tomorrow", summary: "Release at 09:00 after review signs off." },
  ];

  return (
    <Ask
      title="Choose a release window"
      options={summary}
      you
      state={answer ? "answered" : "open"}
      answer={answer}
      onAnswer={(reply) => {
        if (!("choice" in reply)) return;
        const option = summary.find((item) => item.id === reply.choice);
        if (option) setAnswer({ text: option.label, at: fmtTime(Date.now()) });
      }}
    />
  );
}
```

## Accessibility

Every answer is a button named by its words, one Tab stop each, after the question in reading order: a choice, Done, an offer, Not doing it, Hold, Allow or Deny. On an ask that takes several, each choice is a checkbox named by its words in a group named Choices, and Answer stays disabled until one is ticked. Other reports `aria-expanded` and gives its field the focus; Escape closes the field and puts the focus back on Other, as words told do, and a line told is heard as it arrives. The field is named "Your answer", and its button sends. A busy answer keeps its focus. When the control with the focus goes because the ask was answered, held, withdrawn or gone on from, the focus moves to the line that took its place. A place line and its one press are read in order, and an approval has no field, so nothing takes keys for words. An error is announced. For anyone else what it offers is a plain list, and no control is drawn.

- Enter + Space: Presses an answer, or opens the field from Other
- Space: Ticks or clears a choice on an ask that takes several
- Enter: Answers with the words in the field
- shift+enter: Starts a new line in the field
- Esc: Closes the field opened from Other
- Enter: Opens the place a device or source ask waits on

## API reference

### Ask

- `kind` (`"choice" | "task" | "approval"`, default `"choice"`): What it asks of the person. A task draws Done, Not doing it and Hold; an approval Allow and Deny, and nothing else.
- `title` (`string`)
- `question` (`string`)
- `body` (`ReactNode`)
- `comparison` (`DecisionComparison`)
- `options` (`readonly DecisionOption[]`, default `[]`)
- `later` (`boolean`, default `false`)
- `choices` (`readonly string[]`, default `[]`): A choice's answers, in the asker's order, of equal weight. Up to four labels of up to 60 characters (Crew's bound). None: the field alone.
- `multiple` (`boolean`, default `false`): A choice of at least two that takes several: its answers are boxes, and Answer, off until one is ticked, gives every ticked one at once (`{ choices }`).
- `offers` (`readonly string[]`, default `[]`): A task's offers, in the asker's order: what its asker would do instead, such as "Open the payment page for me". An offer, like Hold and the person's own words, is told to the asker through `onAnswer` and leaves the ask open; the product keeps it open.
- `other` (`boolean`, default `false`): "Other" after a choice's answers opens one field for the person's own words. A choice with none always has the field; a task always offers Other, and an approval never has one.
- `otherwise` (`string`): What the asker does if nobody answers, in the asker's words: the line after "Otherwise". Every ask has one; leave it out only where the host already shows it (a list row's `sub`).
- `askedOf` (`ReactNode`): The person it is put to: their name, said as "Asked of" to anyone else and beside the answer. Leave it out where the message already says it over its words (`ReplyQuote` `asked`), so it is said once.
- `you` (`boolean`, default `false`): The reader is that person: the choices press and the field takes words. Anyone else reads the choices as plain words, and "Asked of" names the person.
- `state` (`"open" | "waiting" | "held" | "answered" | "withdrawn" | "gone-on"`, default `"open"`): `held`: a task put off, which says On hold and still takes an answer.
- `answeredIn` (`"anywhere" | "device" | "source"`, default `"anywhere"`): Where it can be answered. `device` and `source` draw no answers and no item: the place line, the machine where one is given, and one press that opens the place.
- `device` (`ReactNode`): With `answeredIn="device"`: the machine the answer waits on ("Ada's MacBook Pro").
- `onOpen` (`() => void`): Opens the place, for the person asked. With `answeredIn="device"` or `"source"`, the one press the ask draws; a row that is the press itself leaves it out.
- `openLabel` (`string`, default `"Open"`): The press's words. name the place where it is known ("Open Keep").
- `answer` (`{ readonly text: string; readonly at: ReactNode }`): With `answered`: what the person gave, and when, in the kit's clock (`fmtTime`, `fmtDayTime`).
- `onAnswer` (`(reply: AskReply) => void | Promise<unknown>`): A choice pressed or words sent. A promise keeps the pressed button busy until it settles. Words sent leave the field once they are told: when the call returns, or when its promise fulfils, with no `error` standing then; a promise that rejects, or an `error` set, keeps them.
- `told` (`readonly AskTold[]`, default `[]`): On an open ask: what the person has told the asker without ending it (their words, an offer), oldest first, a line each that its label leads ("You said"). The words keep their lines.
- `seats` (`AskSeats`): An ask about seats: its lines and the way to review them, in place of the choices and the field.
- `error` (`ReactNode`): The answer did not land: what happened and what to do, under the choices (announced).
- `rootStyle` (`RootStyle`): Typed StyleX override: where the ask sits.

Rest props go to `<div>` props.
