1# Select 2 3The **<Select\>** component provides a drop-down list box that allows users to select among multiple options. 4 5> **NOTE** 6> 7> This component is supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version. 8 9## Child Components 10 11Not supported 12 13## APIs 14 15Select(options: Array\<[SelectOption](#selectoption)\>) 16 17## SelectOption 18 19| Name| Type | Mandatory| Description | 20| ------ | ----------------------------------- | ---- | -------------- | 21| value | [ResourceStr](ts-types.md#resourcestr) | Yes | Value of an option in the drop-down list box.| 22| icon | [ResourceStr](ts-types.md#resourcestr) | No | Icon of an option in the drop-down list box.| 23 24## Attributes 25 26In addition to the [universal attributes](ts-universal-attributes-size.md), the following attributes are supported. 27 28| Name | Type | Description | 29| ----------------------- | ------------------------------------- | --------------------------------------------- | 30| selected | number | Index of the initial selected option in the drop-down list box. The index of the first option is **0**.<br>If this attribute is not set, the default value **-1** is used, indicating that no option is selected.| 31| value | string | Text of the drop-down button. By default, it will be replaced by the content of the selected option.| 32| font | [Font](ts-types.md#font) | Text font of the drop-down button.<br>Default value:<br>{<br>size: '16fp',<br>weight: FontWeight.Medium<br>} | 33| fontColor | [ResourceColor](ts-types.md#resourcecolor) | Text color of the drop-down button.<br>Default value: **'\#E6FFFFFF'**| 34| selectedOptionBgColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of the selected option in the drop-down list box.<br>Default value: **'\#33007DFF'**| 35| selectedOptionFont | [Font](ts-types.md#font) | Text font of the selected option in the drop-down list box.<br>Default value:<br>{<br>size: '16fp',<br>weight: FontWeight.Regular<br>} | 36| selectedOptionFontColor | [ResourceColor](ts-types.md#resourcecolor) | Text color of the selected option in the drop-down list box.<br>Default value: **'\#ff007dff'**| 37| optionBgColor | [ResourceColor](ts-types.md#resourcecolor) | Background color of an option in the drop-down list box.<br>Default value: **'\#ffffffff'**| 38| optionFont | [Font](ts-types.md#font) | Text font of an option in the drop-down list box.<br>Default value:<br>{<br>size: '16fp',<br>weight: FontWeight.Regular<br>} | 39| optionFontColor | [ResourceColor](ts-types.md#resourcecolor) | Text color of an option in the drop-down list box.<br>Default value: **'\#ff182431'**| 40 41## Events 42 43| Name | Description | 44| ------------------------------------------------------------ | ------------------------------------------------------------ | 45| onSelect(callback: (index: number, value?: string) => void) | Invoked when an option in the drop-down list box is selected.<br>**index**: index of the selected option.<br>**value**: value of the selected option.| 46 47## Example 48 49```ts 50// xxx.ets 51@Entry 52@Component 53struct SelectExample { 54 build() { 55 Column() { 56 Select([{ value: 'aaa', icon: "/common/public_icon.svg" }, 57 { value: 'bbb', icon: "/common/public_icon.svg" }, 58 { value: 'ccc', icon: "/common/public_icon.svg" }, 59 { value: 'ddd', icon: "/common/public_icon.svg" }]) 60 .selected(2) 61 .value('TTTTT') 62 .font({ size: 16, weight: 500 }) 63 .fontColor('#182431') 64 .selectedOptionFont({ size: 16, weight: 400 }) 65 .optionFont({ size: 16, weight: 400 }) 66 .onSelect((index: number) => { 67 console.info('Select:' + index) 68 }) 69 }.width('100%') 70 } 71} 72``` 73 74 75