Skip to content

Commit ec1daab

Browse files
authored
Merge pull request #20 from lin-mt/develop
fix: 修改的属性名称是第一个必选属性时,丢失必选信息
2 parents a676e30 + 19c6120 commit ec1daab

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/JsonSchemaEditor/index.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,12 @@ const JsonSchemaEditor = forwardRef<JsonSchemaEditorHandle, SchemaEditorProps>(
130130
parent[lastKey] = Object.fromEntries(
131131
Object.entries(current).map(([key, value]) => {
132132
if (key === oldKey) {
133-
const requiredIndex = parent['required']?.indexOf(oldKey);
134-
if (requiredIndex && requiredIndex !== -1) {
135-
parent['required'].splice(requiredIndex, 1);
136-
parent['required'].push(newKey);
133+
const parentRequired = parent['required'];
134+
if (parentRequired) {
135+
const requiredIndex = parentRequired.indexOf(oldKey);
136+
if (requiredIndex >= 0) {
137+
parentRequired.splice(requiredIndex, 1, newKey);
138+
}
137139
}
138140
return [newKey, value];
139141
}

0 commit comments

Comments
 (0)