diff --git a/src/renderer/src/components/MaterialTypeManagementDialog.tsx b/src/renderer/src/components/MaterialTypeManagementDialog.tsx index 1887d29..a247280 100644 --- a/src/renderer/src/components/MaterialTypeManagementDialog.tsx +++ b/src/renderer/src/components/MaterialTypeManagementDialog.tsx @@ -147,13 +147,16 @@ export const MaterialTypeManagementDialog: React.FC [...prev, newRow]) - // Start editing the material name cell - const newIndex = rows.length - setTimeout(() => { - setEditingCell({ rowIndex: newIndex, field: 'materialName' }) - setEditValue('') - }, 0) + + // 在 setRows 回调中计算索引并设置编辑状态 + setRows((prev) => { + const newIndex = prev.length + setTimeout(() => { + setEditingCell({ rowIndex: newIndex, field: 'materialName' }) + setEditValue('') + }, 0) + return [...prev, newRow] + }) } // Delete row