diff --git a/docs/en-US/component/select-v2.md b/docs/en-US/component/select-v2.md index 91142026a9..484a2e2e16 100644 --- a/docs/en-US/component/select-v2.md +++ b/docs/en-US/component/select-v2.md @@ -3,7 +3,7 @@ title: Virtualized Select lang: en-US --- -# Select V2 virtualized selector +# Select V2 virtualized selector ^(beta) :::tip @@ -131,19 +131,39 @@ select-v2/remote-search ::: -## use value-key +## Use value-key attribute -:::demo when `options.value` is an object, you should set a unique identity key name for value +when `options.value` is an object, you should set a unique identity key name for value + +::: tip + +Before ^(2.4.0), `value-key` was used both as the unique value of the selected object and as an alias for the value in `options`. Now `value-key` is only used as the unique value of the selected object, and the alias for the value in options is `props.value`. + +::: + +:::demo select-v2/use-valueKey ::: +## Aliases for custom options ^(2.4.2) + +When your `options` format is different from the default format, you can customize the alias of the `options` through the `props` attribute + +:::demo + +select-v2/props + +::: + ## SelectV2 Attributes | Name | Description | Type | Accepted Values | Default | | ----------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------- | --------------------------------------------------------------------------------------------------------- | ------------- | | model-value / v-model | biding value | string / number / boolean / object | — | — | +| options | data of the options, the key of `value` and `label` can be customize by `props` | Array | — | — | +| props ^(2.4.2) | configuration options, see the following table | object | — | — | | multiple | is multiple | boolean | — | false | | disabled | is disabled | boolean | — | false | | value-key | unique identity key name for value, required when value is an object | string | — | value | @@ -183,6 +203,15 @@ select-v2/use-valueKey | loading-text | 远程加载时显示的文字 | string | — | 加载中 | --> +## props + +| Attribute | Description | Type | Default | +| --------- | --------------------------------------------------------------- | ------ | -------- | +| value | specify which key of node object is used as the node's value | string | value | +| label | specify which key of node object is used as the node's label | string | label | +| options | specify which key of node object is used as the node's children | string | options | +| disabled | specify which key of node object is used as the node's disabled | string | disabled | + ## SelectV2 Events | Name | Description | Params | diff --git a/docs/examples/select-v2/props.vue b/docs/examples/select-v2/props.vue new file mode 100644 index 0000000000..8b356b24e6 --- /dev/null +++ b/docs/examples/select-v2/props.vue @@ -0,0 +1,25 @@ + + + diff --git a/packages/components/select-v2/src/defaults.ts b/packages/components/select-v2/src/defaults.ts index 31cd4a80c6..975fd8bdf6 100644 --- a/packages/components/select-v2/src/defaults.ts +++ b/packages/components/select-v2/src/defaults.ts @@ -1,26 +1,28 @@ import { placements } from '@popperjs/core' -import { definePropType, isValidComponentSize } from '@element-plus/utils' +import { useSizeProp } from '@element-plus/hooks' +import { buildProps, definePropType, iconPropType } from '@element-plus/utils' import { useTooltipContentProps } from '@element-plus/components/tooltip' import { CircleClose } from '@element-plus/icons-vue' -import type { Component, PropType } from 'vue' -import type { ComponentSize } from '@element-plus/constants' -import type { OptionType } from './select.types' +import { defaultProps } from './useProps' + +import type { Option, OptionType } from './select.types' +import type { Props } from './useProps' import type { Options, Placement } from '@element-plus/components/popper' -export const SelectProps = { +export const SelectProps = buildProps({ allowCreate: Boolean, autocomplete: { - type: String as PropType<'none' | 'both' | 'list' | 'inline'>, + type: definePropType<'none' | 'both' | 'list' | 'inline'>(String), default: 'none', }, automaticDropdown: Boolean, clearable: Boolean, clearIcon: { - type: [String, Object] as PropType, + type: iconPropType, default: CircleClose, }, effect: { - type: String as PropType<'light' | 'dark' | string>, + type: definePropType<'light' | 'dark' | string>(String), default: 'light', }, collapseTags: Boolean, @@ -52,9 +54,11 @@ export const SelectProps = { loading: Boolean, loadingText: String, label: String, - modelValue: [Array, String, Number, Boolean, Object] as PropType< - any[] | string | number | boolean | Record | any - >, + modelValue: { + type: definePropType< + any[] | string | number | boolean | Record | any + >([Array, String, Number, Boolean, Object]), + }, multiple: Boolean, multipleLimit: { type: Number, @@ -69,7 +73,7 @@ export const SelectProps = { default: true, }, options: { - type: Array as PropType, + type: definePropType(Array), required: true, }, placeholder: { @@ -85,13 +89,14 @@ export const SelectProps = { default: '', }, popperOptions: { - type: Object as PropType>, + type: definePropType>(Object), default: () => ({} as Partial), }, remote: Boolean, - size: { - type: String as PropType, - validator: isValidComponentSize, + size: useSizeProp, + props: { + type: definePropType(Object), + default: () => defaultProps, }, valueKey: { type: String, @@ -110,15 +115,18 @@ export const SelectProps = { values: placements, default: 'bottom-start', }, -} +} as const) -export const OptionProps = { +export const OptionProps = buildProps({ data: Array, disabled: Boolean, hovering: Boolean, - item: Object, + item: { + type: definePropType