From dd56a7fdafa208575790b9827f4328fdc8acbbdd Mon Sep 17 00:00:00 2001 From: myron Date: Sat, 21 Sep 2024 16:35:21 +0800 Subject: [PATCH] fix(TreeSelect): mulitple set true has empty selection tag (#3328) * fix(TimePicker): fixed only support hh:mm format * fix(TimePicker): disabled position only is start * fix(Upload): fixed vue error on uploadPastedFiles is false * docs: add readonly in api * fix(TreeSelect): mulitple set true has empty selection tag * chore: update test snap * style: code style fixed --- .../__snapshots__/index.test.jsx.snap | 35 +++++-------------- src/tree-select/useTreeSelect.ts | 4 +-- src/tree-select/utils.ts | 10 ++++++ 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/src/tree-select/__tests__/__snapshots__/index.test.jsx.snap b/src/tree-select/__tests__/__snapshots__/index.test.jsx.snap index 499c5bb68..86be716a8 100644 --- a/src/tree-select/__tests__/__snapshots__/index.test.jsx.snap +++ b/src/tree-select/__tests__/__snapshots__/index.test.jsx.snap @@ -465,49 +465,30 @@ exports[`TreeSelect > :props > :minCollapsedNum 1`] = ` exports[`TreeSelect > :props > :multiple 1`] = `
-
- - - - -
-
+ /> + > + 请选择 + diff --git a/src/tree-select/useTreeSelect.ts b/src/tree-select/useTreeSelect.ts index 31b6ac482..3dedea45c 100644 --- a/src/tree-select/useTreeSelect.ts +++ b/src/tree-select/useTreeSelect.ts @@ -12,7 +12,7 @@ import { TreeOptionData, TreeKeysType } from '../common'; import useVModel from '../hooks/useVModel'; import useDefaultValue from '../hooks/useDefaultValue'; import { SelectInputProps } from '../select-input'; -import { getNodeDataByValue } from './utils'; +import { getNodeDataByValue, normalizeArray } from './utils'; const DEFAULT_KEYS = { label: 'label', @@ -107,7 +107,7 @@ export default function useTreeSelect(props: TdTreeSelectProps, context: SetupCo // multiple tree select node info list function getMultipleNodeInfo(): TreeOptionData[] { const { value } = treeSelectValue; - const list = Array.isArray(value) ? value : [value]; + const list = normalizeArray(value); if (treeRef.value) { return list.map((item) => { const finalValue = typeof item === 'object' ? item.value : item; diff --git a/src/tree-select/utils.ts b/src/tree-select/utils.ts index eaf24c885..fe59984b4 100644 --- a/src/tree-select/utils.ts +++ b/src/tree-select/utils.ts @@ -1,6 +1,8 @@ +import isNil from 'lodash/isNil'; import lodashGet from 'lodash/get'; import lodashSet from 'lodash/set'; import { TreeOptionData, TreeKeysType } from '../common'; +import type { TreeSelectValue } from './type'; export function getNodeDataByValue( values: Array, @@ -47,4 +49,12 @@ export function getNodeDataByValue( return values.map((value) => results.get(value)); } +export function normalizeArray(value: TreeSelectValue) { + if (isNil(value)) { + return []; + } + + return Array.isArray(value) ? value : [value]; +} + export default {};