Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(TreeSelect): mulitple set true has empty selection tag #3328

Merged
merged 14 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
9 changes: 9 additions & 0 deletions src/tree-select/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import isNil from 'lodash/isNil';
import lodashGet from 'lodash/get';
import lodashSet from 'lodash/set';
import { TreeOptionData, TreeKeysType } from '../common';
Expand Down Expand Up @@ -47,4 +48,12 @@ export function getNodeDataByValue(
return values.map((value) => results.get(value));
}

export function normalizeArray(value: any) {
myronliu347 marked this conversation as resolved.
Show resolved Hide resolved
if (isNil(value)) {
return [];
}

return Array.isArray(value) ? value : [value];
}

export default {};
Loading