Skip to content

Commit 8b5097a

Browse files
committed
Ignore JS Events in handleEdit
1 parent 629e8d9 commit 8b5097a

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

src/ButtonPanels.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export const InputButtons: React.FC<{
260260
<div className="jer-confirm-buttons">
261261
{!hideOk && (
262262
// Pass an anonymous function to prevent passing event to onOk
263-
<div onClick={() => onOk()} ref={editConfirmRef as React.RefObject<HTMLDivElement>}>
263+
<div onClick={onOk} ref={editConfirmRef as React.RefObject<HTMLDivElement>}>
264264
<Icon name="ok" nodeData={nodeData} />
265265
</div>
266266
)}

src/ValueNodeWrapper.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
} from './types'
2121
import { useTheme, useTreeState } from './contexts'
2222
import { getCustomNode, type CustomNodeData } from './CustomNode'
23-
import { filterNode, getNextOrPrevious, matchEnumType } from './helpers'
23+
import { filterNode, getNextOrPrevious, isJsEvent, matchEnumType } from './helpers'
2424
import { useCommon, useDragNDrop } from './hooks'
2525
import { KeyDisplay } from './KeyDisplay'
2626

@@ -209,7 +209,7 @@ export const ValueNodeWrapper: React.FC<ValueNodeProps> = (props) => {
209209
setCurrentlyEditingElement(null)
210210
setPreviousValue(null)
211211
let newValue: JsonData
212-
if (inputValue !== undefined) newValue = inputValue as JsonData
212+
if (inputValue !== undefined && !isJsEvent(inputValue)) newValue = inputValue as JsonData
213213
else {
214214
switch (dataType) {
215215
case 'object':

src/helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ import {
1919
export const isCollection = (value: unknown): value is Record<string, unknown> | unknown[] =>
2020
value !== null && typeof value === 'object' && !(value instanceof Date)
2121

22+
export const isJsEvent = (value: unknown) => {
23+
return (
24+
value &&
25+
typeof value === 'object' &&
26+
'type' in value &&
27+
'target' in value &&
28+
'preventDefault' in value &&
29+
typeof value.preventDefault === 'function'
30+
)
31+
}
32+
2233
/**
2334
* FILTERING
2435
*/

0 commit comments

Comments
 (0)