fix: 修复ATP模型编辑时下拉选项无法选择的问题

问题描述:
在编辑ATP模型时,下拉框中已选中的选项无法被重新选择。

根本原因:
CreatableSingleSelect组件使用了mode="tags"的Select,但onChange处理逻辑不够完善,
导致在某些情况下选择操作无法正确更新表单值。

解决方案:
1. 将value的规范化逻辑提取为独立变量,提高代码可读性
2. 改进onChange处理逻辑,明确处理空数组和非空数组的情况
3. 添加tokenSeparators配置,支持逗号分隔输入新值

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
chengkai3
2026-06-27 22:42:36 +08:00
parent bb265387c9
commit 91c9877e0a
+13 -2
View File
@@ -19,6 +19,8 @@ export function CreatableSingleSelect({
value,
onChange,
}: CreatableSingleSelectProps) {
const normalizedValue = value !== null && value !== undefined && value !== "" ? [value] : [];
return (
<Select
allowClear={allowClear}
@@ -27,8 +29,17 @@ export function CreatableSingleSelect({
maxCount={1}
options={options}
placeholder={placeholder}
value={value !== null && value !== undefined ? [value] : []}
onChange={(nextValue) => onChange?.(Array.isArray(nextValue) ? (nextValue.at(-1) ?? "") : "")}
value={normalizedValue}
onChange={(nextValue) => {
if (Array.isArray(nextValue)) {
if (nextValue.length === 0) {
onChange?.("");
} else {
onChange?.(nextValue[nextValue.length - 1] ?? "");
}
}
}}
tokenSeparators={[","]}
/>
);
}