Skip to content

Commit

Permalink
fix(TreeSelect): mulitple set true has empty selection tag (#3328)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
myronliu347 committed Sep 21, 2024
1 parent 64dd416 commit dd56a7f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
35 changes: 8 additions & 27 deletions src/tree-select/__tests__/__snapshots__/index.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -465,49 +465,30 @@ exports[`TreeSelect > :props > :minCollapsedNum 1`] = `

exports[`TreeSelect > :props > :multiple 1`] = `
<div
class="t-select-input t-select-input--multiple t-tree-select"
class="t-select-input t-select-input--multiple t-select-input--empty t-tree-select"
>
<div
class="t-input__wrap t-tag-input t-tag-input--break-line t-tag-input--with-tag t-tag-input__with-suffix-icon"
class="t-input__wrap t-tag-input t-tag-input--break-line t-is-empty t-tag-input__with-suffix-icon"
>
<div
class="t-input t-is-readonly t-input--prefix t-input--suffix"
>
<div
class="t-input__prefix"
>
<div
class="t-tag t-tag--default t-tag--dark t-tag--ellipsis t-tag--close"
>
<span
class="t-tag--text"
style="max-width: 300px;"
/>
<svg
class="t-icon t-icon-close t-tag__icon-close"
fill="none"
height="1em"
viewBox="0 0 24 24"
width="1em"
>
<path
d="M7.05 5.64L12 10.59l4.95-4.95 1.41 1.41L13.41 12l4.95 4.95-1.41 1.41L12 13.41l-4.95 4.95-1.41-1.41L10.59 12 5.64 7.05l1.41-1.41z"
fill="currentColor"
/>
</svg>
</div>
</div>
/>
<input
autocomplete=""
class="t-input__inner t-input--soft-hidden"
placeholder=""
class="t-input__inner"
placeholder="请选择"
readonly="readonly"
type="text"
unselectable="on"
/>
<span
class="t-input__input-pre"
/>
>
请选择
</span>
<span
class="t-input__suffix t-input__suffix-icon"
>
Expand Down
4 changes: 2 additions & 2 deletions src/tree-select/useTreeSelect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/tree-select/utils.ts
Original file line number Diff line number Diff line change
@@ -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<string | number>,
Expand Down Expand Up @@ -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 {};

0 comments on commit dd56a7f

Please sign in to comment.