# Approval Mode (/docs/agent-ui/components/approval-mode)

Use an approval mode beside a [composer](./composer.mdx) when people decide how often the agent stops to ask, like approving every tool call or letting it edit files on its own. It's a button that shows the current mode and opens a menu of modes, each with a description, and it marks a risky one.

<Example caption="Press Approvals, then choose Full access. The menu closes, and the button shows Full access with a warning mark.">
  <ApprovalModeExample />

  ```tsx tab="React"
  "use client";
  import type { ApprovalModeOption } from "@kind-ui/agent-ui";
  import { useState } from "react";
  import { ApprovalMode } from "@/components/ui/approval-mode";

  const modes: ApprovalModeOption[] = [
    { value: "ask", label: "Ask every time", description: "Approve each tool call" },
    { value: "edits", label: "Allow edits", description: "Edit files without asking" },
    { value: "full", label: "Full access", description: "Run anything without asking", danger: true },
  ];

  export default function ApprovalModeExample() {
    const [value, setValue] = useState("ask");

    return <ApprovalMode modes={modes} value={value} onValueChange={setValue} learnMoreHref="#agent" />;
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import type { ApprovalModeOption } from "@kind-ui/agent-ui";
  import { ref } from "vue";
  import { ApprovalMode } from "@/components/ui/vue/approval-mode";

  const modes: ApprovalModeOption[] = [
    { value: "ask", label: "Ask every time", description: "Approve each tool call" },
    { value: "edits", label: "Allow edits", description: "Edit files without asking" },
    { value: "full", label: "Full access", description: "Run anything without asking", danger: true },
  ];

  const value = ref("ask");
  </script>

  <template>
    <ApprovalMode :modes="modes" v-model:value="value" learn-more-href="#agent" />
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import type { ApprovalModeOption } from "@kind-ui/agent-ui";
    import { ApprovalMode } from "@/components/ui/svelte/approval-mode/index.js";

    const modes: ApprovalModeOption[] = [
      { value: "ask", label: "Ask every time", description: "Approve each tool call" },
      { value: "edits", label: "Allow edits", description: "Edit files without asking" },
      { value: "full", label: "Full access", description: "Run anything without asking", danger: true },
    ];

    let value = $state("ask");
  </script>

  <ApprovalMode {modes} bind:value learnMoreHref="#agent" />
  ```

  ```tsx tab="Solid"
  import type { ApprovalModeOption } from "@kind-ui/agent-ui";
  import { createSignal } from "solid-js";
  import { ApprovalMode } from "@/components/ui/solid/approval-mode";

  const modes: ApprovalModeOption[] = [
    { value: "ask", label: "Ask every time", description: "Approve each tool call" },
    { value: "edits", label: "Allow edits", description: "Edit files without asking" },
    { value: "full", label: "Full access", description: "Run anything without asking", danger: true },
  ];

  export default function ApprovalModeExample() {
    const [value, setValue] = createSignal("ask");

    return <ApprovalMode modes={modes} value={value()} onValueChange={setValue} learnMoreHref="#agent" />;
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/approval-mode
```

```bash tab="Web Components"
npx shadcn@latest add @kind-ui/approval-mode-web
```

```bash tab="Vue"
npx shadcn@latest add @kind-ui/approval-mode-vue
```

```bash tab="Svelte"
npx shadcn@latest add @kind-ui/approval-mode-svelte
```

```bash tab="Solid"
npx shadcn@latest add @kind-ui/approval-mode-solid
```

## Composition [#composition]

```text
ApprovalMode
├── ApprovalModeTrigger
└── ApprovalModeContent
    └── ApprovalModeRows
```

`ApprovalMode` is a group named by its `label` and the current mode, around UI SDK's Menu. `ApprovalModeTrigger` is UI SDK's `MenuTrigger`, a button that shows a shield icon, the mode's label and, for a risky mode, a warning mark, unless you pass children. `ApprovalModeContent` is UI SDK's `MenuContent`: one radio group headed by the `label`, then an optional **Learn more** item. `ApprovalModeRows` draws the modes inside it as radio items. `ApprovalMode` renders the trigger and content when you pass no children.

## Usage [#usage]

### Modes [#modes]

Pass `modes`, in order. Each has a `value`, which must be unique, a `label` and an optional `description`, a second line under the label. A mode with `danger: true` lets the agent do more without asking: its row says "Risky" in the danger color, and when it's chosen the button shows a warning mark.

The button is named by the `label` and the mode, like "Approvals, Ask every time", with ", risky" after a risky mode. The `label` is "Approvals" by default and also heads the menu.

### Value [#value]

Pass `value` and `onValueChange` to control the mode, or `defaultValue` to start with one. Choosing a mode closes the menu, and `onValueChange` gets the new `value` with the reason `item-press`. Call `details.cancel()` to keep the old mode. To have a person confirm a risky mode first, cancel the change in `onValueChange`, ask, and set `value` once they agree.

```tsx
<ApprovalMode
  modes={modes}
  value={value}
  onValueChange={(next, details) => {
    if (modes.find((mode) => mode.value === next)?.danger) {
      details.cancel();
      confirmFullAccess().then((ok) => ok && setValue(next));
    } else setValue(next);
  }}
/>
```

The Approval Mode doesn't act on the mode. Your app reads it and decides which tool calls need approval.

### Learn More [#learn-more]

Pass `learnMoreHref` to add a **Learn more** link after the modes, or `onLearnMore` to handle it yourself. `onLearnMore` gets the `learnMoreHref`, if there is one, and the reason `item-press`.

### Opening [#opening]

Pass `open` and `onOpenChange` to control whether the menu is open, or `defaultOpen` to start open. `onOpenChange` gets UI SDK Menu's reason, like `trigger-press` or `escape-key`. Set `disabled` to keep the button from opening the menu; it also closes an open one.

### Keyboard [#keyboard]

The button is one Tab stop. Enter, Space or Down Arrow opens the menu with focus on the first mode, and the arrow keys move between the modes and **Learn more**. Typing a letter moves to the next mode whose label starts with it. Enter or Space chooses a mode and closes the menu. Escape closes it without a change, with focus back on the button.

### Presentation and Motion [#presentation-and-motion]

The menu opens as a popover below the button. With `presentation="auto"`, the default, it's a bottom sheet on small touch screens instead; pass `"popover"` or `"sheet"` to choose one. The popover rises and fades in. Under `prefers-reduced-motion`, or with `motion="reduced"`, it only fades, over 120 ms, and with `motion="none"` it opens at once.

## API Reference [#api-reference]

### ApprovalModeOptions

An Approval Mode's options: the menu's, plus its modes and the chosen one.

| Prop             | Type                                                                                       | Description                                                                                                                                                                                    |
| ---------------- | ------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `label?`         | `string \| undefined`                                                                      | Names the trigger. Each menu has its own default. Names the menu, and with the mode the trigger: "Approvals, Ask every time". Default: `"Approvals"`                                           |
| `open?`          | `boolean \| undefined`                                                                     | Whether the menu is open. Passing it controls it: change it in `onOpenChange`.                                                                                                                 |
| `defaultOpen?`   | `boolean \| undefined`                                                                     | Whether the menu is open at first, when `open` isn't passed. Default: `false`                                                                                                                  |
| `onOpenChange?`  | `((open: boolean, details: ChangeDetails<MenuOpenChangeReason>) => void) \| undefined`     | Called when the menu opens or closes, with UI SDK Menu's reason.                                                                                                                               |
| `presentation?`  | `"auto" \| "popover" \| "sheet"`                                                           | How the menu presents. `"auto"` is a bottom sheet on small touch screens and a popover elsewhere. Default: `"auto"`                                                                            |
| `disabled?`      | `boolean \| undefined`                                                                     | Whether the trigger can't open the menu. Default: `false`                                                                                                                                      |
| `motion?`        | `"auto" \| "none" \| "reduced"`                                                            | How the menu opens and closes. `"auto"` follows `prefers-reduced-motion`. Default: `"auto"`                                                                                                    |
| `modes?`         | `ApprovalModeOption[] \| undefined`                                                        | The modes, in order, each a radio item. Every `value` is unique. A `danger` mode lets the agent do more without asking: it's drawn with a warning mark, which reads "Risky". Default: `[]`     |
| `value?`         | `string \| undefined`                                                                      | The chosen mode's `value`. Passing it controls it: change it in `onValueChange`. A value that isn't one of the `modes` chooses none, and the trigger shows only the `label`.                   |
| `defaultValue?`  | `string \| undefined`                                                                      | The mode chosen at first, when `value` isn't passed. Without either, none is.                                                                                                                  |
| `onValueChange?` | `((value: string, details: ChangeDetails<ApprovalModeChangeReason>) => void) \| undefined` | Called when a person or an `api` call chooses another mode. Cancel it to keep the mode, or to ask first.                                                                                       |
| `learnMoreHref?` | `string \| undefined`                                                                      | Where the menu's Learn more link goes. Without it or `onLearnMore`, the menu has no Learn more item.                                                                                           |
| `onLearnMore?`   | `((href: string \| undefined, details: ChangeDetails<"item-press">) => void) \| undefined` | Called when a person chooses Learn more, with the `learnMoreHref` if there is one. The link opens whatever it does: call `details.event?.preventDefault()` to route it yourself.               |
| `agentConfirm?`  | `boolean \| undefined`                                                                     | Whether an agent needs a person before it acts on the menu, since changing the mode widens or narrows what it may do without asking. Renders `data-agent-confirm` on the root. Default: `true` |

Vue, Svelte and Solid take the same props. Controlled props and callbacks are spelled as each framework expects:

| React                    | Vue                              | Svelte                        | Solid                    |
| ------------------------ | -------------------------------- | ----------------------------- | ------------------------ |
| `open`, `onOpenChange`   | `v-model:open`, `@open-change`   | `bind:open`, `onOpenChange`   | `open`, `onOpenChange`   |
| `value`, `onValueChange` | `v-model:value`, `@value-change` | `bind:value`, `onValueChange` | `value`, `onValueChange` |
| `onLearnMore`            | `@learn-more`                    | `onLearnMore`                 | `onLearnMore`            |

### Agent [#agent]

An agent connected with `createAgent` finds the approval mode by its name, like "Approvals, Ask every time", and reads `open` and `value`. It lists every mode by `value` and label. `setValue` takes a mode's `value` and refuses an unknown one; it's offered only while the menu is enabled and holds a mode, and it changes the mode whether the menu is open or closed. `open` is offered while the menu is closed and enabled, and `close` while it's open.

Changing the mode widens or narrows what the agent may do without asking, so with `agentConfirm`, on by default, the root renders `data-agent-confirm` and every action needs a person to confirm it. Set `agentConfirm={false}` only when your app confirms these changes another way.

### ApprovalModeAgentActions

| Prop       | Type                                        | Description                                                                                                                                                                                |
| ---------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `open`     | `(() => boolean) \| undefined`              | Opens the menu. Offered only while it's closed and enabled. Returns whether the change was accepted.                                                                                       |
| `close`    | `(() => boolean) \| undefined`              | Closes the menu. Offered only while it's open. Returns whether the change was accepted.                                                                                                    |
| `setValue` | `((value: string) => boolean) \| undefined` | Chooses a mode by its `value`. Offered only while the menu is enabled and holds a mode. Returns whether the change was accepted: `false` for an unknown value, or one the owner cancelled. |

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. On `<kind-approval-mode>`, set `modes`, `value` and `open` as properties and `learn-more-href` and `agent-confirm` as attributes, and listen for `modechange`, with the mode as `event.detail.value`, and `openchange`. Add the `can-learn-more` attribute to listen for `learnmore` instead of following a link. The element fills in its button and menu when it has no children.
</Caption>
