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:
@@ -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={[","]}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user