Skip to content

Commit 10e3451

Browse files
Update src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 886f549 commit 10e3451

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/theme/JSONSchemaViewer/components/SchemaItem/SchemaItem.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ export default function SchemaItem({
3939
}: SchemaItemProps): JSX.Element {
4040
const { jsonPointer, level } = useSchemaHierarchyContext()
4141
const { defaultExpandDepth } = useJSVOptionsContext()
42-
43-
// Determine if Collapsible should be open or closed by default
44-
const isOpenByDefault = level < (defaultExpandDepth ?? 0)
4542

43+
// Determine if Collapsible should be open or closed by default
44+
// Depth is measured from root (root level = 0). Clamp negatives to 0.
45+
const expandDepth = Math.max(0, defaultExpandDepth ?? 0)
46+
const isOpenByDefault = level <= expandDepth
4647
// Notice : "deprecated" started at 2019-09
4748
let typedSchema = schema as JSONSchema_Draft_2019_09
4849
let isDeprecated =

0 commit comments

Comments
 (0)