# Select Component The Select component presents options in a dropdown menu. This guide focuses on the usage of the `` component. For information on dropdown menu items, see the [``](/en/docs/2/components/menu#menu-item-api) section. ## Usage {#usage} Import the component: ```js import 'mdui/components/select.js'; import 'mdui/components/menu-item.js'; ``` Import the TypeScript type: ```ts import type { Select } from 'mdui/components/select.js'; import type { MenuItem } from 'mdui/components/menu-item.js'; ``` Example: ```html,example,playgroundId=353 Item 1 Item 2 ``` ## Examples {#examples} ### Variants {#example-variant} Use the `variant` attribute to change the select's shape. ```html,example,expandable,playgroundId=354 Item 1 Item 2 Item 1 Item 2 ``` ### Multiple Selection {#example-multiple} By default, the component allows only a single selection. The `value` of the `` component corresponds to the `value` of the currently selected [``](/en/docs/2/components/menu#menu-item-api). To allow multiple selections, add the `multiple` attribute. In this case, the `value` of `` becomes an array containing the `value` properties of the currently selected [``](/en/docs/2/components/menu#menu-item-api) components. Note: When multiple selection is enabled, the `value` property of `` is an array and can only be accessed and accessed and updated in JavaScript. ```html,example,expandable,playgroundId=355 Item 1 Item 2 Item 3 ``` ### Helper Text {#example-helper-text} Use the `label` attribute to display a label above the select. ```html,example,expandable,playgroundId=356 Item 1 Item 2 ``` Use the `placeholder` attribute to display placeholder text when no value is selected. ```html,example,expandable,playgroundId=357 Item 1 Item 2 ``` Use the `helper` attribute to display helper text at the bottom of the select. Alternatively, use the `helper` slot to provide helper text. ```html,example,expandable,playgroundId=358 Item 1 Item 2 Item 1 Item 2 Supporting text ``` ### Read-Only State {#example-readonly} To make the select read-only, add the `readonly` attribute. ```html,example,expandable,playgroundId=359 Item 1 Item 2 ``` ### Disabled State {#example-disabled} To disable the select, add the `disabled` attribute. ```html,example,expandable,playgroundId=360 Item 1 Item 2 ``` ### Clearable {#example-clearable} The `clearable` attribute displays a clear button on the right when the select has a value. ```html,example,expandable,playgroundId=361 Item 1 Item 2 ``` You can customize the clear button using the `clear` slot. ```html,example,expandable,playgroundId=362 Item 1 Item 2 ``` ### Dropdown Menu Position {#example-placement} Use the `placement` attribute to set the dropdown menu position. ```html,example,expandable,playgroundId=363 Item 1 Item 2 ``` ### Text Alignment {#example-end-aligned} To align the text to the right, add the `end-aligned` attribute. ```html,example,expandable,playgroundId=364 Item 1 Item 2 ``` ### Prefix, Suffix, and Icons {#example-prefix-suffix} Use the `icon` and `end-icon` attributes to add Material Icons to the left and right of the select. Alternatively, use the `icon` and `end-icon` slots to add elements to the select. ```html,example,expandable,playgroundId=365 Item 1 Item 2

Item 1 Item 2 ``` Use the `prefix` and `suffix` attributes to add text to the left and right of the select. Alternatively, use the `prefix` and `suffix` slots to add text elements. They appear when the select is focused or has a value. ```html,example,expandable,playgroundId=366 Item 1 Item 2

Item 1 Item 2 $ /100 ```