From 481a0153be1d3458dd0ba367063b22951aee24e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Sun, 17 Nov 2024 05:31:38 +0800 Subject: [PATCH 1/7] feat(Select): `collapsibleItems` params expanded options --- src/select-input/interface.ts | 8 ++++++++ src/select-input/select-input.tsx | 11 +++++++++-- src/select-input/useMultiple.tsx | 7 ++++--- src/select/_example/collapsed.vue | 26 +++++++++++++------------- src/select/select.tsx | 1 + src/tag-input/interface.ts | 4 +++- src/tag-input/tag-input.tsx | 12 ++++++++++-- src/tag-input/useTagList.tsx | 4 +++- 8 files changed, 51 insertions(+), 22 deletions(-) diff --git a/src/select-input/interface.ts b/src/select-input/interface.ts index dd95eb87f6..33c74d5673 100644 --- a/src/select-input/interface.ts +++ b/src/select-input/interface.ts @@ -1,4 +1,5 @@ import { TdSelectInputProps } from './type'; +import { PropType } from 'vue'; export interface SelectInputCommonProperties { autofocus?: TdSelectInputProps['autofocus']; @@ -18,3 +19,10 @@ export interface SelectInputCommonProperties { onMouseenter?: TdSelectInputProps['onMouseenter']; onMouseleave?: TdSelectInputProps['onMouseleave']; } + +export interface SelectInputProps extends TdSelectInputProps { + /** + * 不对外暴露,参数穿透options, 给SelectInput/SelectInput 自定义选中项呈现的内容和多选状态下设置折叠项内容 + */ + options: any[]; +} diff --git a/src/select-input/select-input.tsx b/src/select-input/select-input.tsx index b87c5fca58..6037cb7d64 100644 --- a/src/select-input/select-input.tsx +++ b/src/select-input/select-input.tsx @@ -1,12 +1,13 @@ import { computed, defineComponent, onBeforeUnmount, onMounted, PropType, ref, SetupContext, toRefs, watch } from 'vue'; import Popup, { PopupInstanceFunctions, PopupProps, PopupVisibleChangeContext } from '../popup'; import props from './props'; -import { TdSelectInputProps } from './type'; +import type { TdSelectInputProps } from './type'; import useSingle, { SelectInputValueDisplayOptions } from './useSingle'; import useMultiple from './useMultiple'; import useOverlayInnerStyle from './useOverlayInnerStyle'; import { usePrefixClass } from '../hooks/useConfig'; import { useTNodeJSX } from '../hooks'; +import type { SelectInputProps } from './interface'; const useComponentClassName = () => { return { @@ -32,9 +33,15 @@ export default defineComponent({ valueDisplayOptions: { type: Object as PropType, }, + /** + * 不对外暴露,参数穿透options, 给SelectInput/SelectInput 自定义选中项呈现的内容和多选状态下设置折叠项内容 + */ + options: { + type: Array as PropType, + }, }, - setup(props: TdSelectInputProps & { valueDisplayOptions: SelectInputValueDisplayOptions }, context: SetupContext) { + setup(props: SelectInputProps & { valueDisplayOptions: SelectInputValueDisplayOptions }, context: SetupContext) { const { NAME_CLASS, BASE_CLASS_BORDERLESS, BASE_CLASS_MULTIPLE, BASE_CLASS_POPUP_VISIBLE, BASE_CLASS_EMPTY } = useComponentClassName(); const classPrefix = usePrefixClass(); diff --git a/src/select-input/useMultiple.tsx b/src/select-input/useMultiple.tsx index 45bc18ecce..e6c4a9faac 100644 --- a/src/select-input/useMultiple.tsx +++ b/src/select-input/useMultiple.tsx @@ -1,7 +1,7 @@ import { SetupContext, computed, ref, toRefs, Ref } from 'vue'; import isObject from 'lodash/isObject'; -import { TdSelectInputProps, SelectInputChangeContext, SelectInputKeys } from './type'; -import { SelectInputCommonProperties } from './interface'; +import type { SelectInputChangeContext, SelectInputKeys } from './type'; +import type { SelectInputCommonProperties, SelectInputProps } from './interface'; import TagInput, { TagInputValue, TagInputProps } from '../tag-input'; import Loading from '../loading'; import useDefault from '../hooks/useDefaultValue'; @@ -23,7 +23,7 @@ const DEFAULT_KEYS = { }; export default function useMultiple( - props: TdSelectInputProps, + props: SelectInputProps, context: SetupContext, popupRef: Ref, ) { @@ -99,6 +99,7 @@ export default function useMultiple( collapsedItems: props.collapsedItems, tag: props.tag, value: tags.value, + options: props.options, valueDisplay: props.valueDisplay, inputValue: p.popupVisible && p.allowInput ? tInputValue.value : '', inputProps: { diff --git a/src/select/_example/collapsed.vue b/src/select/_example/collapsed.vue index 788ca780b5..17e7451bb2 100644 --- a/src/select/_example/collapsed.vue +++ b/src/select/_example/collapsed.vue @@ -39,10 +39,10 @@ :disabled="disabled" :readonly="readonly" > -