Skip to content

Commit 5bb146c

Browse files
committed
Make new collection nodes start opened up
1 parent 05a16da commit 5bb146c

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ This component is heavily inspired by [react-json-view](https://github.com/mac-s
584584
585585
## Changelog
586586
587-
- **1.11.1**: Bug fix for invalid state when changing type to Collection node
587+
- **1.11.3**: Bug fix for invalid state when changing type to Collection node
588588
- **1.11.0**:
589589
- Improve CSS definitions to prevent properties from being overridden by the host environment's CSS
590590
- Add `rootFontSize` prop to set the "base" size for the component

src/CollectionNode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = ({
8484
useEffect(() => {
8585
if (collapseState !== null && doesPathMatch(path)) {
8686
hasBeenOpened.current = true
87-
setCollapsed(collapseState.open)
87+
setCollapsed(collapseState.collapsed)
8888
}
8989
}, [collapseState])
9090

@@ -134,7 +134,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = ({
134134
const handleCollapse = (e: React.MouseEvent) => {
135135
if (e.getModifierState('Alt')) {
136136
hasBeenOpened.current = true
137-
setCollapseState({ open: !collapsed, path })
137+
setCollapseState({ collapsed: !collapsed, path })
138138
return
139139
}
140140
if (!(currentlyEditingElement && currentlyEditingElement.includes(pathString))) {

src/TreeStateProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { type CollectionKey } from './types'
88

99
interface CollapseAllState {
1010
path: CollectionKey[]
11-
open: boolean
11+
collapsed: boolean
1212
}
1313
interface TreeStateContext {
1414
collapseState: CollapseAllState | null

src/ValueNodeWrapper.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
4949
customNodeDefinitions,
5050
} = props
5151
const { getStyles } = useTheme()
52-
const { currentlyEditingElement, setCurrentlyEditingElement } = useTreeState()
52+
const { currentlyEditingElement, setCurrentlyEditingElement, setCollapseState } = useTreeState()
5353
const [value, setValue] = useState<typeof data | CollectionData>(
5454
// Bad things happen when you put a function into useState
5555
typeof data === 'function' ? INVALID_FUNCTION_STRING : data
@@ -140,6 +140,7 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
140140
updateValue(newValue as ValueData)
141141
onEdit(newValue, path)
142142
setCurrentlyEditingElement(null)
143+
setCollapseState({ path, collapsed: false })
143144
setDataType(type)
144145
}
145146
}

0 commit comments

Comments
 (0)