---
title: "single-choice-dropdown"
description: "Overview"
permalink: /docs/build/ui-components/all-ui-components/single-choice-dropdown/
---
# single-choice-dropdown

## Overview

<Info title={"Version compatibility"}>

* `single-choice-dropdown` is supported in all versions of the JourneyApps Container and Runtime.
* It received several functional updates in version **4.84.0** of the JourneyApps Runtime.

</Info>

A `single-choice-dropdown` component allows users to make a single selection from a pre-defined set of options in a dropdown component.

### Basic Example

**main.view\.xml**

```xml
<var name="selected_country" type="single-choice">
    <option key="us">USA</option>
    <option key="uk">UK</option>
    <option key="de">Germany</option>
    ...
</var>

<single-choice-dropdown label="Country of residence" bind="selected_country" required="false" />
```

![](./media/spaces-2f9tchlr67elhbojpvhhud-2fuploads-2fgit-blob-1a3216174c2d5167c10b76f7ea1f787f3f80608b-2fsingle-choice-dropdown-example-selected-c8494808.png)

![](./media/spaces-2f9tchlr67elhbojpvhhud-2fuploads-2fgit-blob-59358e3fd6dc7cc9391415df3d27f64cc9dc4572-2fsingle-choice-dropdown-example-options-e033cb76.png)

## Advanced Attributes

### `align-dialog-content`

<SyntaxCard type={["center", "left", "right"]} defaultValue="center" introduced="4.84.0" />

Specifies how the content of the list of options dialog should be aligned. This includes the display value of each option, as well as the header text of the dialog.

```xml
<single-choice-dropdown label="Country of residence" align-dialog-content="left" bind="selected_country" />
```

### `dialog-title`

<SyntaxCard type="string (static text, format string, or JS/TS function result)" defaultValue={'"Choose an option"'} introduced="4.84.0" />

Header text of the dialog that displays the list of options of the `single-choice-dropdown`.

```xml
<single-choice-dropdown label="Country of residence" dialog-title="Choose the country of residence" bind="selected_country" />
```

### `empty-message`

<SyntaxCard type="string (static text, format string, or JS/TS function result)" defaultValue="unset" introduced="4.84.0" />

Text that is displayed if no options are available to list once the user opens the `single-choice-dropdown`.

```xml
<single-choice-dropdown label="Country of residence" bind="selected_country" empty-message="No countries are available. Please contact your administrator." />
```

### `search-controls`

<SyntaxCard type={["auto", "none", "show"]} defaultValue="auto" introduced="4.84.0" />

Set the visibility of the search box of the `single-choice-dropdown` component. `auto` shows the search box when the list of options contains 12 options or more. `none` never shows the search box, and `show` always shows the search box at the top of the list of options.

```xml
<single-choice-dropdown label="Country of residence" bind="selected_country" search-controls="show" />
```

### `align-content`

<AttributeReference label="align-content" href="/docs/build/ui-components/common-attributes/align-content/" badge="advanced" tone="muted" />

### `align-label`

<AttributeReference label="align-label" href="/docs/build/ui-components/common-attributes/align-label/" badge="advanced" tone="muted" />

### `clear-button-visibility`

<AttributeReference label="clear-button-visibility" href="/docs/build/ui-components/common-attributes/clear-button-visibility/" badge="advanced" tone="muted" />

### `disabled`

<AttributeReference label="disabled" href="/docs/build/ui-components/common-attributes/disabled/" badge="advanced" tone="muted" />

### `icon-position`

<AttributeReference label="icon-position" href="/docs/build/ui-components/common-attributes/icon-position/" badge="advanced" tone="muted" />

### `id`

<AttributeReference label="id" href="/docs/build/ui-components/common-attributes/id/" badge="advanced" tone="muted" />

### `label-case`

<AttributeReference label="label-case" href="/docs/build/ui-components/common-attributes/label-case/" badge="advanced" tone="muted" />

### `label-color`

<AttributeReference label="label-color" href="/docs/build/ui-components/common-attributes/label-color/" badge="advanced" tone="muted" />

### `modifier-text`

<AttributeReference label="modifier-text" href="/docs/build/ui-components/common-attributes/modifier-text/" badge="advanced" tone="muted" />

### `on-change`

<AttributeReference label="on-change" href="/docs/build/ui-components/common-attributes/on-change/" badge="advanced" tone="muted" />

### `placeholder`

<AttributeReference label="placeholder" href="/docs/build/ui-components/common-attributes/placeholder/" badge="advanced" tone="muted" />

### `show-if`

<AttributeReference label="show-if" href="/docs/build/ui-components/common-attributes/show-if/" badge="advanced" tone="muted" />

### `hide-if`

<AttributeReference label="hide-if" href="/docs/build/ui-components/common-attributes/hide-if/" badge="advanced" tone="muted" />

## Common Attributes

### `border-radius`

<AttributeReference label="border-radius" href="/docs/build/ui-components/common-attributes/border-radius/" badge="new" sinceVersion="5.1.0" />

### `bind`

<AttributeReference label="bind" href="/docs/build/ui-components/common-attributes/bind/" />

### `label`

<AttributeReference label="label" href="/docs/build/ui-components/common-attributes/label/" />

### `required`

<AttributeReference label="required" href="/docs/build/ui-components/common-attributes/required/" />

## Component Methods

The following component methods are available when an [`id`](/docs/build/ui-components/common-attributes/id/) is assigned to the component and `component.singleChoiceDropdown({id:'my-id'})` is called from JS/TS:

### `clear`

Programmatically clear the selected value bound to the `single-choice-dropdown`.

### `clearSearch`

Programmatically clear a value entered into the search box.

### `openDropdown`

Programmatically open the list of items.

### `closeDropdown`

Programmatically close the list of items.

### `scrollDown`

Programmatically scroll down the list of items when the `single-choice-dropdown` is opened.

### `scrollIntoView`

Programmatically scroll until the `single-choice-dropdown` is visible in the view.

### `scrollUp`

Programmatically scroll up the list of items when the `single-choice-dropdown` is opened.

### `selectItem`

Programmatically select an item from the list by its label.

**main.view\.xml**

```xml
<var name="favorite_color" type="single-choice">
    <option key="green">Green</option>
    <option key="red">Red</option>
    <option key="yellow">Yellow</option>
</var>

<single-choice-dropdown id="my-dropdown" bind="favorite_color" label="Favorite Color" />
```

**main.js**

```javascript
function select() {
    component.singleChoiceDropdown({id: 'my-dropdown'}).openDropdown(); // Need to open the dropdown first
    component.singleChoiceDropdown({id: 'my-dropdown'}).selectItem('Yellow');
}
```

### `selectItemByIndex`

Programmatically select an item from the list by its index. **Note**: Indexes begin at 1.

**main.view\.xml**

```xml
<var name="favorite_color" type="single-choice">
    <option key="green">Green</option>
    <option key="red">Red</option>
    <option key="yellow">Yellow</option>
</var>

<single-choice-dropdown id="my-dropdown" bind="favorite_color" label="Favorite Color" />
```

**main.js**

```javascript
function select() {
    component.singleChoiceDropdown({id: 'my-dropdown'}).openDropdown(); // Need to open the dropdown first
    component.singleChoiceDropdown({id: 'my-dropdown'}).selectItemByIndex(2);
    // Selects "Red"
}
```

### `setSearch`

Programmatically enter a search value and triggers a search of the `single-choice-dropdown`.
