Closed DespuesLeeWallace closed 2 years ago
hey, please reference to this part of the doc: https://github.com/shunjizhan/react-folder-tree#-custom-onclick-for-node-names
Hi, yeah sorry, I meant the event javascript object. The one that is used in mouse callbacks (ev,...), i.e. to get the mouse location on the screen, etc
ummm I think the mouse location is not a concern of folder tree itself, so maybe it's better to use another lib to track it.
For example use this https://github.com/streamich/react-use/blob/master/docs/useMouse.md to track mouse location, and when the node is clicked, read the location from it
something like
const {docX, docY, posX, posY, elX, elY, elW, elH} = useMouse(ref);
const onNameClick = ({ defaultOnClick, nodeData }) => {
// use the mouse location from above
};
mmm, I see.
I was thinking more of something like this:
const onNameClick = ({ defaultOnClick, nodeData, event }) => {
// We can get all the usual properties (i.e. button, clientX, metaKey, movementX, region, target, etc)
}
To be able to access the event object like any other onClick callback lets you. Anyway, I added it in TreeNode:
const handleNameClick = (event) => {
const defaultOnClick = selectMe;
if (onNameClick && typeof onNameClick === "function") {
!isEditing && onNameClick({ defaultOnClick, nodeData, event });
} else {
defaultOnClick();
}
};
But thanks for the tip, I didn't know about useMouse(). I am new to React and js
I need it to get the mouse coordinates when a node is clicked so I can show a menu.