Skip to content

Commit cad5867

Browse files
committed
When switching to a custom node, leave it expanded and not editing
1 parent 6d2f7c8 commit cad5867

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/ValueNodeWrapper.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
4545
customNodeDefinitions,
4646
} = props
4747
const { getStyles } = useTheme()
48-
const { setCurrentlyEditingElement } = useTreeState()
48+
const { setCurrentlyEditingElement, setCollapseState } = useTreeState()
4949
const [value, setValue] = useState<typeof data | CollectionData>(
5050
// Bad things happen when you put a function into useState
5151
typeof data === 'function' ? INVALID_FUNCTION_STRING : data
@@ -133,6 +133,9 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
133133
if (customNode) {
134134
onEdit(customNode.defaultValue, path)
135135
setDataType(type)
136+
// Custom nodes will be instantiated expanded and NOT editing
137+
setCurrentlyEditingElement(null)
138+
setCollapseState({ path, collapsed: false })
136139
} else {
137140
const newValue = convertValue(
138141
value,

src/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export interface JsonEditorProps {
2929
restrictAdd?: boolean | FilterFunction
3030
restrictTypeSelection?: boolean | DataType[] | TypeFilterFunction
3131
restrictDrag?: boolean | FilterFunction
32-
// restrictKeyEdit?: boolean | FilterFunction
3332
searchText?: string
3433
searchFilter?: 'key' | 'value' | 'all' | SearchFilterFunction
3534
searchDebounceTime?: number

0 commit comments

Comments
 (0)