-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass Node ref to event at srcElement prop #125
Conversation
Ran into a issue while testing, lets hold on the pr for now. |
Cannot use forwardRef as it only ever references the first node loaded and does not change when selecting a new node. Instead I am able to pass a ref to the node back on the onDragEnd event by setting the srcElement prop of the event to the node itself. |
src/symbols/Node/Node.tsx
Outdated
@@ -143,14 +144,10 @@ export const Node: FC<Partial<NodeProps>> = ({ | |||
onEnter = () => undefined, | |||
onLeave = () => undefined | |||
}) => { | |||
const nodeRef = useRef<SVGRectElement>(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const nodeRef = useRef<SVGRectElement>(null); | |
const nodeRef = useRef<SVGRectElement | null>(null); |
@@ -225,6 +222,8 @@ export const Node: FC<Partial<NodeProps>> = ({ | |||
if (!isDisabled && canDrag) { | |||
// @ts-ignore | |||
event.dragType = getDragType(false); | |||
// @ts-ignore | |||
event.srcElement = nodeRef.current; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was the srcElement
there before or is this a new prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a new prop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a prop on the actual pointer event on event.event
but this is one level up on the top level event. So you are able to see event.srcElement
: the element that the onDragEnd event occurred from and event.event.srcElement
: element the pointerup
event happened on, same as event.event.target
.
PR Type
What kind of change does this PR introduce?
What is the current behavior?
No ability to use ref with Node symbol.
What is the new behavior?
You can now pass a ref to a Node to keep a reference to it.
Does this PR introduce a breaking change?