# Code

## Props

<table><thead><tr><th width="227.66666666666666">Props</th><th width="356.92465335639054">Data Type</th><th>Required</th></tr></thead><tbody><tr><td>label</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>info</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>name</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>placeholder</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>id</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td>value</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td>children</td><td>-HTML tags<br>-Custom Components<br><em>(MenuOption, MenuHeader and MenuDivider)</em></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2705">✅</span></td></tr><tr><td>search</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>helptext</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>readOnly</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>error</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>errorMessage</td><td>string</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>disabled</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>autoposition</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>showVisuals</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>checkSelectedItems</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>removeSelectedItems</td><td>boolean</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr><tr><td>onChange</td><td>function event</td><td><span data-gb-custom-inline data-tag="emoji" data-code="274c">❌</span></td></tr></tbody></table>

{% hint style="info" %}
The properties marked with a **?** are optionals.
{% endhint %}

### Functionality and Internal Structure

This form control is going to be structured using the same children components implemented in the [Menu](https://2600hz.gitbook.io/sds/sds-components/simple-components/menu) component, replicating the logic and flexibility at creating options for the dropdown menu. The only difference, is that this component already has a toggle feature that allows to open or close the menu, at the same time it reflects the select item, replacing the original `placeholder` prop value.

![](https://1808678181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_703CkzPx9rque70Qj%2Fuploads%2FAEpEGNKvyFHTl8Sl0MTy%2Fimage.png?alt=media\&token=d380b4a6-bffd-4375-ba4b-0e8fc4451c98)->![](https://1808678181-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_703CkzPx9rque70Qj%2Fuploads%2FroBqteVGf7TRG9tHUZWZ%2Fimage.png?alt=media\&token=91a58c76-ca72-43ea-88c5-23e5d9487e42)

### autoposition

This feature allows developers to not worry about the correct location of the `Menu` or `MenuBox` component on the screen, because this will relocate it automatically, placing it on the top, bottom, right or left; it all depends on the available space.

### showVisuals

In case there were used avatars or icons at creating options for the dropdown menu, `showVisuals` will allow the component to display them also on the input box of the dropdown component at the moment selecting one of the items on the menu. By default, this feature is not active on the Dropdown component.

### removeSelectedItem

Once an item has been clicked and selected, it will be removed from the list.

### checkSelectedItem

Once an item has been clicked and selected, it will show a darker background as a visual indicator.

### Event Response

| Property                                                                                                                   | Data Type |
| -------------------------------------------------------------------------------------------------------------------------- | --------- |
| id                                                                                                                         | string    |
| name                                                                                                                       | string    |
| label                                                                                                                      | string    |
| value                                                                                                                      | string    |
| <p>description<br><em>(This property will appear only if the description prop exists in the MenuOption component)</em></p> | string    |

### OnChange

```jsx
import React, {useState} from 'react';
import {Dropdown, MenuOption, MenuDivider, Menuheader} from '@2600hz/sds-react-components';

const Example = ()=>{
    const [selectedItem, setSeletedItem] = useState('');
    
    const updateState = (e)=>{
        setSelectedItem(e.value);
    }
    
    return(
        <div className='container'>
            <Dropdown id='dropdown' onChange={updateState}>
                <MenuOption description="Lorem ipsum"> Element 1 </MenuOption>
                <MenuOption> Element 2 </MenuOption>
                <MenuOption> Element 3 </MenuOption>
                <MenuOption> Element 4 </MenuOption>
            </Dropdown>
        </div>
    )
}

```

## Components Dependency

For this component elaboration, there were used the following internal components:

* [Label](https://2600hz.gitbook.io/sds/sds-components/form-controls/label)
* [Menu](https://2600hz.gitbook.io/sds/sds-components/simple-components/menu)
* Menu Header
* Menu Divider
* [Menu Option](https://2600hz.gitbook.io/sds/sds-components/form-controls/dropdown/broken-reference)
  * [Avatar](https://2600hz.gitbook.io/sds/sds-components/simple-components/avatar)
  * [Telicon](https://2600hz.gitbook.io/sds/sds-components/simple-components/telicon)

## Live Demo

For detailed code usage documentation, see the Storybooks for each framework below.

### React

{% embed url="<https://sipster-react-component-storybook.netlify.app/?path=%2Fstory%2Fform-controls-dropdown--basic-dropdown>" %}
