Skip to content

Commit 38112a4

Browse files
committed
fix: default shouldExpandNodeInitially to false for collapsed nodes. #59
1 parent b1c5b0d commit 38112a4

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ export default function Demo() {
735735
collapsed={2}
736736
shouldExpandNodeInitially={(isExpanded, { value, keys, level }) => {
737737
if (keys.length > 0 && keys[0] == "object") {
738-
return true
738+
return false
739739
}
740740
return isExpanded
741741
}}

core/src/comps/KeyValues.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ export const KeyValues = <T extends object>(props: KeyValuesProps<T>) => {
2525
const defaultExpanded =
2626
typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
2727
const isExpanded = expands[expandKey] ?? defaultExpanded;
28-
if (
29-
expands[expandKey] === undefined &&
30-
shouldExpandNodeInitially &&
31-
shouldExpandNodeInitially(isExpanded, { value, keys, level })
32-
) {
28+
const shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, { value, keys, level });
29+
if (expands[expandKey] === undefined && !shouldExpand) {
3330
return null;
3431
}
3532
if (isExpanded) {

core/src/comps/NestedClose.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ export const NestedClose = <T extends object>(props: NestedCloseProps<T>) => {
1919
typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
2020
const isExpanded = expands[expandKey] ?? defaultExpanded;
2121
const len = Object.keys(value!).length;
22-
if (
23-
expands[expandKey] === undefined &&
24-
shouldExpandNodeInitially &&
25-
shouldExpandNodeInitially(isExpanded, { value, keys, level })
26-
) {
22+
const shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, { value, keys, level });
23+
if (expands[expandKey] === undefined && !shouldExpand) {
2724
return null;
2825
}
2926
if (isExpanded || len === 0) {

core/src/comps/NestedOpen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ export const NestedOpen = <T extends object>(props: NestedOpenProps<T>) => {
2626
typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
2727
const isObject = typeof value === 'object';
2828
let isExpanded = expands[expandKey] ?? defaultExpanded;
29-
const shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(isExpanded, { value, keys, level });
30-
if (expands[expandKey] === undefined && shouldExpand !== undefined) {
31-
isExpanded = shouldExpand;
29+
const shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, { value, keys, level });
30+
if (expands[expandKey] === undefined && !shouldExpand) {
31+
isExpanded = !shouldExpand;
3232
}
3333
const click = () => {
3434
const opt = { expand: !isExpanded, value, keyid: expandKey, keyName };

0 commit comments

Comments
 (0)