# Select button

Source: https://ecosphere.dev/docs/forms/select-button (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A disclosure button opening a menu, for a choice a native select cannot show.

`import { EcoSelectButton } from "vue-ecosphere"`

## With a label

The count beside the name is the decision. Arrow keys move, Escape closes.

Vue (vue-ecosphere):

```vue
<EcoSelectButton v-model="block" label="Home room" :options="[
  { label: 'Block A', value: 'a', hint: '9 rooms, 4 unassigned' },
  { label: 'Block B', value: 'b', hint: '12 rooms, all assigned' },
  …
]" first />
```

React (react-ecosphere):

```tsx
const [block, setBlock] = useState<string | null>("a");

<EcoSelectButton value={block} onChange={setBlock} label="Home room" options={[
  { label: "Block A", value: "a", hint: "9 rooms, 4 unassigned" },
  { label: "Block B", value: "b", hint: "12 rooms, all assigned" },
  …
]} first />
```

## Beside a text input, in a two-column field grid

It matches input exactly: no seam.

Vue (vue-ecosphere):

```vue
<EcoFieldGrid first>
  <EcoSelectButton v-model="grade" label="Class" :options="classes" first />
  <EcoTextField v-model="teacher" label="Class teacher" first />
</EcoFieldGrid>
```

React (react-ecosphere):

```tsx
const [grade, setGrade] = useState<number | null>(9);
const [teacher, setTeacher] = useState("Priya Nair");

<EcoFieldGrid first>
  <EcoSelectButton value={grade} onChange={setGrade} label="Class" options={classes} first />
  <EcoTextField value={teacher} onChange={setTeacher} label="Class teacher" first />
</EcoFieldGrid>
```

## Without a field

Vue (vue-ecosphere):

```vue
<EcoSelectButton v-model="lab" :options="labs" aria-label="Lab" />
```

React (react-ecosphere):

```tsx
const [lab, setLab] = useState<string | null>("204");

<EcoSelectButton value={lab} onChange={setLab} options={labs} aria-label="Lab" />
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string \| number \| null` | null | The chosen value. |
| `v-model:open` | `boolean` | false | Whether the menu is open. |
| `options` | `EcoOption[]` | — | { label, value, hint?, count?, disabled? } — the hint is shown beside the label, in the trigger too. |
| `ariaLabel` | `string` | — | Trigger name when there is no label. |
| `separator` | `string` | " · " | Join between label and hint in the trigger. |
| `placeholder` | `string` | "Choose an option" | Trigger text while nothing is chosen. |
| `label / required / hint / error / first / disabled` | `—` | — | Field props; the label sits above, never in the trigger. |
| `#value / #option` | `slot` | — | Custom trigger text / option content. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value / onChange` | `string \| number \| null` | null | The chosen value. |
| `open / onOpenChange` | `boolean` | false | Whether the menu is open. |
| `options` | `EcoOption[]` | — | { label, value, hint?, count?, disabled? } — the hint is shown beside the label, in the trigger too. |
| `aria-label` | `string` | — | Trigger name when there is no label. |
| `separator` | `string` | " · " | Join between label and hint in the trigger. |
| `placeholder` | `string` | "Choose an option" | Trigger text while nothing is chosen. |
| `label / required / hint / error / first / disabled` | `—` | — | Field props; the label sits above, never in the trigger. |
| `value / option` | `({ option }) => ReactNode / ({ option, selected }) => ReactNode` | — | Custom trigger text / option content. |
