# Settings Menu (/docs/agent-ui/components/settings-menu)

Use a settings menu in a [composer](./composer.mdx) for settings someone changes now and then, like turning web search on or picking how long answers are. It's an icon button that opens a menu of switches, and of choices that each open a submenu of their options.

<Example caption="Press Settings, then press Memory to turn it on; the menu stays open. Open Response style and choose Detailed, and the row shows the new option.">
  <SettingsMenuExample />

  ```tsx tab="React"
  "use client";
  import type { SettingsValues } from "@kind-ui/agent-ui";
  import { useState } from "react";
  import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/composer";
  import { SettingsMenu, type SettingsMenuSetting } from "@/components/ui/settings-menu";

  const settings: SettingsMenuSetting[] = [
    {
      type: "toggle",
      id: "search",
      label: "Web search",
      description: "Look things up before answering",
    },
    { type: "toggle", id: "memory", label: "Memory" },
    {
      type: "choice",
      id: "style",
      label: "Response style",
      options: [
        { value: "concise", label: "Concise" },
        { value: "balanced", label: "Balanced" },
        { value: "detailed", label: "Detailed" },
      ],
    },
  ];

  export default function SettingsMenuExample() {
    const [values, setValues] = useState<SettingsValues>({ search: true, memory: false, style: "balanced" });

    return (
      <Composer aria-label="Message" onSubmit={() => new Promise<void>((resolve) => setTimeout(resolve, 1000))}>
        <ComposerInput aria-label="Prompt" placeholder="Ask anything" />
        <SettingsMenu
          style={{ gridArea: "attach" }}
          settings={settings}
          values={values}
          onValuesChange={setValues}
        />
        <ComposerSubmit />
      </Composer>
    );
  }
  ```

  ```vue tab="Vue"
  <script setup lang="ts">
  import type { SettingsValues } from "@kind-ui/agent-ui";
  import { shallowRef } from "vue";
  import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/vue/composer";
  import { SettingsMenu, type SettingsMenuSetting } from "@/components/ui/vue/settings-menu";

  const settings: SettingsMenuSetting[] = [
    {
      type: "toggle",
      id: "search",
      label: "Web search",
      description: "Look things up before answering",
    },
    { type: "toggle", id: "memory", label: "Memory" },
    {
      type: "choice",
      id: "style",
      label: "Response style",
      options: [
        { value: "concise", label: "Concise" },
        { value: "balanced", label: "Balanced" },
        { value: "detailed", label: "Detailed" },
      ],
    },
  ];

  const values = shallowRef<SettingsValues>({ search: true, memory: false, style: "balanced" });
  const send = () => new Promise<void>((resolve) => setTimeout(resolve, 1000));
  </script>

  <template>
    <Composer aria-label="Message" :on-submit="send">
      <ComposerInput aria-label="Prompt" placeholder="Ask anything" />
      <SettingsMenu v-model:values="values" style="grid-area: attach" :settings="settings" />
      <ComposerSubmit />
    </Composer>
  </template>
  ```

  ```svelte tab="Svelte"
  <script lang="ts">
    import type { SettingsValues } from "@kind-ui/agent-ui";
    import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/svelte/composer/index.js";
    import { SettingsMenu, type SettingsMenuSetting } from "@/components/ui/svelte/settings-menu/index.js";

    const settings: SettingsMenuSetting[] = [
      {
        type: "toggle",
        id: "search",
        label: "Web search",
        description: "Look things up before answering",
      },
      { type: "toggle", id: "memory", label: "Memory" },
      {
        type: "choice",
        id: "style",
        label: "Response style",
        options: [
          { value: "concise", label: "Concise" },
          { value: "balanced", label: "Balanced" },
          { value: "detailed", label: "Detailed" },
        ],
      },
    ];

    let values: SettingsValues = $state.raw({ search: true, memory: false, style: "balanced" });
  </script>

  <Composer aria-label="Message" onSubmit={() => new Promise<void>((resolve) => setTimeout(resolve, 1000))}>
    <ComposerInput aria-label="Prompt" placeholder="Ask anything" />
    <SettingsMenu style="grid-area: attach" {settings} bind:values />
    <ComposerSubmit />
  </Composer>
  ```

  ```tsx tab="Solid"
  import type { SettingsValues } from "@kind-ui/agent-ui";
  import { createSignal } from "solid-js";
  import { Composer, ComposerInput, ComposerSubmit } from "@/components/ui/solid/composer";
  import { SettingsMenu, type SettingsMenuSetting } from "@/components/ui/solid/settings-menu";

  const settings: SettingsMenuSetting[] = [
    {
      type: "toggle",
      id: "search",
      label: "Web search",
      description: "Look things up before answering",
    },
    { type: "toggle", id: "memory", label: "Memory" },
    {
      type: "choice",
      id: "style",
      label: "Response style",
      options: [
        { value: "concise", label: "Concise" },
        { value: "balanced", label: "Balanced" },
        { value: "detailed", label: "Detailed" },
      ],
    },
  ];

  export default function SettingsMenuExample() {
    const [values, setValues] = createSignal<SettingsValues>({
      search: true,
      memory: false,
      style: "balanced",
    });

    return (
      <Composer aria-label="Message" onSubmit={() => new Promise<void>((resolve) => setTimeout(resolve, 1000))}>
        <ComposerInput aria-label="Prompt" placeholder="Ask anything" />
        <SettingsMenu
          style={{ "grid-area": "attach" }}
          settings={settings}
          values={values()}
          onValuesChange={(next) => setValues(next)}
        />
        <ComposerSubmit />
      </Composer>
    );
  }
  ```
</Example>

## Installation [#installation]

```bash tab="React"
npx shadcn@latest add @kind-ui/settings-menu
```

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

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

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

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

## Composition [#composition]

```text
SettingsMenu
├── SettingsMenuTrigger
└── SettingsMenuContent
    └── SettingsMenuRows
```

`SettingsMenu` is a group named by its `label`, around UI SDK's Menu. `SettingsMenuTrigger` is UI SDK's `MenuTrigger`, an icon button named by the `label` that shows a settings icon unless you pass children. `SettingsMenuContent` is UI SDK's `MenuContent`, and `SettingsMenuRows` draws the rows inside it: a switch for each toggle, and a submenu for each choice. `SettingsMenu` renders the trigger and content when you pass no children.

## Usage [#usage]

### Settings [#settings]

Pass `settings`, the rows in order. Each has a `type`, an `id` and a `label`, and every `id` must be unique.

- A `toggle` is a switch, with an optional `description` (a second line under the label). A screen reader hears it as a menu item that's checked or not.
- A `choice` has `options`, each a `value` and a `label`. Its row shows the chosen option's label after its own, and opens a submenu of the options, one of them checked. An option can also have an `icon`, a `group`, under whose label it's listed, and `disabled`, which shows it dimmed: it can still be focused but not chosen.

Either can have an `icon`. In React, it's an image URL or an element, like an inline `<svg>`. Icons are hidden from assistive technology, so the label names the row. The `label` names the button, "Settings" by default.

To pick the model and its effort from the same kind of menu, use [Model Control](./model-control.mdx), a Settings Menu with Model and Effort rows of its own.

### Values [#values]

Pass `values` and `onValuesChange` to control the values, or `defaultValues` to start with some. They're keyed by setting `id`: `true` or `false` for a toggle, an option's `value` for a choice. A toggle without a value is off, and a choice without one shows no option.

Pressing a toggle flips it, and choosing an option sets its choice. Either way the menu stays open, so someone can change several settings at once. `onValuesChange` gets every value and `details.id`, the setting that changed, once per change, with the reason `item-press`. Call `details.cancel()` to refuse it, and the row keeps its old value.

```tsx
<SettingsMenu
  settings={settings}
  values={values}
  onValuesChange={(values, details) => {
    if (details.id === "memory" && !canRemember) details.cancel();
    else setValues(values);
  }}
/>
```

The Settings Menu doesn't act on its values. In the example above, they're kept in state for the app to read when it sends the prompt.

### 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 row, and the arrow keys move between rows. Typing a letter moves to the next row whose label starts with it. Enter or Space flips a toggle. Right Arrow opens a choice's submenu, Enter or Space chooses an option, and Left Arrow or Escape closes only the submenu. Escape closes the menu, 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, where a choice's submenu replaces the level and Left Arrow or Escape goes back; 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. The sheet slides up whatever the motion settings.

## API Reference [#api-reference]

### SettingsMenuOptions

A Settings Menu's options: the menu's, plus its settings and their values.

| Prop              | Type                                                                                   | Description                                                                                                                                                                                                                                     |
| ----------------- | -------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `label?`          | `string \| undefined`                                                                  | Names the trigger. Each menu has its own default. Names the trigger, an icon button. Default: `"Settings"`                                                                                                                                      |
| `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"`                                                                                                                                                     |
| `settings?`       | `SettingsEntry<unknown>[] \| undefined`                                                | The rows, in order: a `toggle` is a switch that keeps the menu open, a `choice` a submenu of its `options` showing the current one. Every `id` is unique. The primitive passes each `icon` through to the render layer untouched. Default: `[]` |
| `values?`         | `SettingsValues \| undefined`                                                          | The values by setting `id`. Passing it controls them: change them in `onValuesChange`.                                                                                                                                                          |
| `defaultValues?`  | `SettingsValues \| undefined`                                                          | The values at first, when `values` isn't passed. A toggle without one is off; a choice without one shows none. Default: `{}`                                                                                                                    |
| `onValuesChange?` | `((values: SettingsValues, details: SettingsMenuChangeDetails) => void) \| undefined`  | Called once per setting a person or an `api` call changes, with every value and the setting's `id` in `details`.                                                                                                                                |

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`     |
| `values`, `onValuesChange` | `v-model:values`, `@values-change` | `bind:values`, `onValuesChange` | `values`, `onValuesChange` |

### Agent [#agent]

An agent connected with `createAgent` finds the settings menu by its label and reads `open` and `values`. It lists every setting by `id` and label. `toggle` takes a toggle's `id` and turns it on or off, or flips it without `on`. `setValue` takes a choice's `id` and one of its option values. Both refuse an unknown `id` or value, or a setting of the other type, and each is offered only while the menu is enabled and holds a setting of its type. They change values whether the menu is open or closed and leave it as it was. `open` is offered while the menu is closed and enabled, and `close` while it's open. None needs a person to confirm.

### SettingsMenuAgentActions

| 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.                                                                                                                                                               |
| `toggle`   | `((id: string, on?: boolean) => boolean) \| undefined`  | Turns a toggle on or off by its `id`, or flips it without `on`. Offered only while the menu is enabled and holds a toggle. Returns whether the change was accepted: `false` for an id that isn't a toggle, or one the owner cancelled.                |
| `setValue` | `((id: string, value: string) => boolean) \| undefined` | Chooses a choice setting's option by their `id` and `value`. Offered only while the menu is enabled and holds a choice. Returns whether the change was accepted: `false` for an unknown id, an unknown or disabled value, or one the owner cancelled. |

<Caption>
  Runs in React, Vue, Svelte, Solid and Web Components. On `<kind-settings-menu>`, set `settings`, `values` and `open` as properties, and listen for `valueschange`, with every value as `event.detail.value` and the setting as `event.detail.id`, and `openchange`. A setting's `icon` is an image URL or an Element, which the element copies into its row. The element fills in its button and menu when it has no children.
</Caption>
