2020-08-13 11:47:56 +08:00
# Dropdown
:::tip
`Dropdown` can be used with embedded [`Option` ](./option ) or [`OptionGroup` ](./option-group ).
:::
## Demos
### Style variants
2021-10-20 01:11:27 +08:00
Available style variants for the [`ui` ](#props-ui ) prop: `primary` / `text` .
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/dropdown/style.vue" ]]
### Size variants
2021-10-20 01:11:27 +08:00
Available size values for the [`ui` ](#props-ui ) prop: `xs` / `s` / `m` / `l` .
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/dropdown/size.vue" ]]
### Using embedded `OptionGroup`s & `Option`s
Can be used with embedded `OptionGroup` s & `Option` s.
[[ demo src="/demo/dropdown/inline.vue" ]]
### Searchable dropdown
2021-10-20 01:11:27 +08:00
Using[`searchable`](#props-searchable) prop to make the component support search functionality.
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/dropdown/searchable.vue" ]]
### Disabled dropdown
Use the `disabled` property in `options` items to disable single option.
[[ demo src="/demo/dropdown/disable.vue" ]]
### Trigger and split
2021-10-20 01:11:27 +08:00
Use the [`trigger` ](#props-trigger ) prop to specify when to open the dropdown menu. Use the [`split` ](#props-split ) prop to separate command button and dropdown button.
2020-08-13 11:47:56 +08:00
[[ demo src="/demo/dropdown/other.vue" ]]
## API
### Props
| Name | Type | Default | Description |
| -- | -- | -- | -- |
2021-10-20 01:11:27 +08:00
| ``ui`` | `string=` | - | [^ui] |
| ``options`` | `Array<Object>=` | `[]` | [^options] |
| ``label`` | `string` | - | The descriptive label of the dropdown button. |
| ``trigger`` | `string=` | `'click'` | When to trigger the dropdown to open. Available values are `'click'` / `'hover'` . |
| ``split`` | `boolean=` | `false` | Whether to split the dropdown button into a command button and a toggle button for the dropdown layer. |
| ``expanded`` | `boolean=` | `false` | [^expanded] |
| ``disabled`` | `boolean=` | `false` | Whether the dropdown is disabled. |
| ``overlay-class`` | `string | Array | Object=` | - | See the [`overlay-class` ](./overlay#props-overlay-class ) prop of the [`Overlay` ](./overlay ) component. |
| ``overlay-style`` | `string | Array | Object=` | - | See the [`overlay-style` ](./overlay#props-overlay-style ) prop of the [`Overlay` ](./overlay ) component. |
2020-08-13 11:47:56 +08:00
^^^ui
Style variants.
+++Enum values
| Value | Description |
| -- | -- |
| `primary` | Primary style. |
| `text` | Text style. |
| `xs` | Extra small. |
| `s` | Small. |
| `m` | Medium. |
| `l` | Large. |
^^^
^^^options
The list of options with the option type being `{label, value, dropdown, disabled, ...}` .
+++Properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The descriptive label of the option. |
| `value` | `*` | The value of the option. |
2021-10-20 01:11:27 +08:00
| `options` | `Array<Object>=` | The child options of current option. The item type is the same as the items of the [`options` ](#props-options ) prop. |
2020-08-13 11:47:56 +08:00
| `disabled` | `boolean=` | Whether the option is disabled. |
+++
^^^
2020-11-04 18:02:44 +08:00
^^^expanded
:::badges
`.sync`
:::
Whether the dropdown menu is expanded.
^^^
2020-08-13 11:47:56 +08:00
### Slots
| Name | Description |
| -- | -- |
2021-10-20 01:11:27 +08:00
| ``default`` | The content of the options dropdown layer. Can be used to place `Option` s or `OptionGroups` s when the [`options` ](#props-options ) prop is not specified. |
| ``before`` | The content before the options in the dropdown layer. |
| ``after`` | The content after the options in the dropdown layer. |
| ``label`` | [^slot-label] |
| ``group-label`` | [^slot-group-label] |
| ``option-label`` | [^slot-option-label] |
| ``option`` | [^slot-option] |
| ``trigger`` | [^slot-trigger] |
2020-08-13 11:47:56 +08:00
2020-12-22 16:33:30 +08:00
^^^slot-label
2021-10-20 01:11:27 +08:00
The content of the select button. Displays the [`label` ](#props-label ) prop by default.
2020-08-13 11:47:56 +08:00
+++Scope properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The descriptive label of the dropdown option. |
+++
^^^
2020-12-22 16:33:30 +08:00
^^^slot-group-label
2020-08-13 11:47:56 +08:00
The label text of each option group (option with child `options` ). Displays the `label` of the option by default.
+++Scope properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The descriptive label of the option group. |
| `disabled` | `boolean=` | Whether the option group is disabled. |
+++
Additionally, custom properties in current option, apart from the listed ones, will also be passes into the scope object via `v-bind` .
^^^
2020-12-22 16:33:30 +08:00
^^^slot-option-label
2020-08-13 11:47:56 +08:00
The label text of each option (option without child `options` ). Displays the `label` of the option by default.
+++Scope properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The descriptive label of the option. |
| `value` | `*` | The value of the option. |
| `selected` | `boolean` | Whether the the option is selected. |
| `disabled` | `boolean=` | Whether the option is disabled. |
+++
Additionally, custom properties in current option, apart from the listed ones, will also be passes into the scope object via `v-bind` .
^^^
2020-12-22 16:33:30 +08:00
^^^slot-option
2020-08-13 11:47:56 +08:00
The entire content area of each option (option without child `options` ). Displays the default content of `Options` component by default.
+++Scope properties
| Name | Type | Description |
| -- | -- | -- |
| `label` | `string` | The descriptive label of the option. |
| `value` | `*` | The value of the option. |
| `selected` | `boolean` | Whether the the option is selected. |
| `disabled` | `boolean=` | Whether the option is disabled. |
+++
Additionally, custom properties in current option, apart from the listed ones, will also be passes into the scope object via `v-bind` .
^^^
2021-02-01 14:18:57 +08:00
^^^slot-trigger
The entire drop-down trigger area. Displays the dropdown button by default.
+++Scope properties
| Name | Type | Description |
| --- | --- | --- |
2021-10-20 01:11:27 +08:00
| `attrs` | `Object` | Attributes that need to be output to the trigger element, including `aria-*` / `disabled` , etc., can be output using `v-bind="attrs"` . |
2021-02-01 14:18:57 +08:00
| `handlers` | `Object` | [^handlers-desc] |
| `expanded` | `boolean` | Whether the dropdown menu is expanded or not. |
| `toggle` | `function(force?: boolean): void` | Used to toggle the expanded state of the dropdown menu. |
+++
^^^
2021-10-29 17:13:10 +08:00
^^^handlers-desc
2021-02-01 14:18:57 +08:00
Event listeners that need to be bound to the trigger element, can be output using `v-on="handlers"` .
:::tip
The element used to bind `handlers` needs to support focus acquisition so that various keyboard interactions can still be triggered properly.
:::
^^^
2020-08-13 11:47:56 +08:00
### Events
| Name | Description |
| -- | -- |
2021-10-20 01:11:27 +08:00
| ``click`` | Triggered when an option is clicked. The callback parameter list is `(value: *=)` . `value` is the `value` property of the option being clicked. Also triggered when `split` is `true` and the command button is clicked, in this case there won't be a `value` argument. |
| ``toggle`` | Triggered when the expanded state is going to change. The callback parameter list is `(expanded: boolean)` . `expanded` denotes whether the dropdown menu is to be expanded or collapsed. |
2020-08-13 11:47:56 +08:00
### Icons
| Name | Description |
| -- | -- |
2021-10-20 01:11:27 +08:00
| ``expand`` | Expand the dropdown layer. |
| ``collapse`` | Collapse the dropdown layer. |