Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 5 additions & 3 deletions packages/components/cascader/core/effect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isNumber, isFunction, cloneDeep } from 'lodash-es';
import { TreeNode, CascaderContextType, TdCascaderProps, TreeNodeValue, TreeNodeModel } from '../interface';
import { cloneDeep, isFunction, isNumber } from 'lodash-es';
import { getFullPathLabel, getTreeValue } from './helper';
import type { CascaderContextType, TdCascaderProps, TreeNode, TreeNodeModel, TreeNodeValue } from '../interface';

/**
* 点击item的副作用
Expand Down Expand Up @@ -47,8 +47,10 @@ export function expendClickEffect(
}

if (!multiple && (node.isLeaf() || checkStrictly) && trigger === 'click') {
if (node.checked) return;

treeStore.resetChecked();
const checked = node.setChecked(!node.checked);
const checked = node.setChecked(true);
const [value] = checked;

// 非受控状态下更新状态
Expand Down
29 changes: 24 additions & 5 deletions packages/components/cascader/core/helper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { isEmpty } from 'lodash-es';
import {
TreeNode,
import type {
CascaderContextType,
TdCascaderProps,
CascaderValue,
TdCascaderProps,
TreeNode,
TreeNodeValue,
TreeOptionData,
} from '../interface';
Expand Down Expand Up @@ -141,6 +141,25 @@ export function isEmptyValues(value: unknown): boolean {
* @returns boolean
*/
export function isValueInvalid(value: CascaderValue, cascaderContext: CascaderContextType) {
const { multiple, showAllLevels } = cascaderContext;
return (multiple && !Array.isArray(value)) || (!multiple && Array.isArray(value) && !showAllLevels);
const { multiple, showAllLevels, valueType } = cascaderContext;

// 多选模式:
// value 必须是数组
if (multiple) {
return !Array.isArray(value);
}

// 单选模式:
// valueType === 'full' 时,使用完整路径数组
if (valueType === 'full') {
return !Array.isArray(value);
}

// 其它情况默认 value 为非数组
// 若是数组,仅在 showAllLevels=true 时合法
if (Array.isArray(value)) {
return !showAllLevels;
}

return false;
}
2 changes: 1 addition & 1 deletion packages/components/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref

const isFormList = formListName && isSameForm;
const mapRef = isFormList ? formListMapRef : formMapRef;
if (!mapRef.current) return;
if (!mapRef?.current) return;

// 注册实例
mapRef.current.set(fullPath, formItemRef);
Expand Down
Loading