-
Notifications
You must be signed in to change notification settings - Fork 4
🐛(frontend) fix phantom selection issue between nodes #126
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,7 @@ export const TreeView = <T,>({ | |
width={width} | ||
paddingTop={10} | ||
paddingBottom={10} | ||
rowHeight={35} | ||
rowHeight={50} | ||
disableDrag={disableDrag} | ||
disableDrop={({ parentNode, dragNodes, index }) => { | ||
if (canDrop) { | ||
|
@@ -327,7 +327,8 @@ const Row = <T,>({ children, ...props }: RowProps<T>) => { | |
const target = e.target as HTMLElement | null; | ||
if (target) { | ||
const isInActionsToolbar = target.closest(".actions"); | ||
const interactiveSelector = 'button, a[href], input, textarea, select, [role="menuitem"], [role="button"]'; | ||
const interactiveSelector = | ||
'button, a[href], input, textarea, select, [role="menuitem"], [role="button"]'; | ||
const isInteractive = target.closest(interactiveSelector); | ||
if (isInActionsToolbar || isInteractive) { | ||
return; | ||
|
@@ -346,6 +347,37 @@ const Row = <T,>({ children, ...props }: RowProps<T>) => { | |
} | ||
}; | ||
|
||
// Block everything if clicking outside the actual row content (between items). | ||
const handleRowMouseEvent = (e: React.MouseEvent<HTMLElement>) => { | ||
const target = e.target as HTMLElement; | ||
const rowContent = e.currentTarget.querySelector( | ||
".c__tree-view--row-content" | ||
); | ||
|
||
// Allow toolbar/interactives (menus, links, inputs…) | ||
const interactiveSelector = | ||
'button, a[href], input, textarea, select, [role="menuitem"], [role="button"]'; | ||
const inToolbar = target.closest(".actions"); | ||
const isInteractive = target.closest(interactiveSelector); | ||
|
||
// Only allow primary click (leave context-menu/drag) | ||
const isPrimaryClick = "button" in e && e.button === 0; | ||
if (!isPrimaryClick) return; | ||
|
||
const inside = !!rowContent && rowContent.contains(target); | ||
const outside = !inside && !inToolbar && !isInteractive; | ||
|
||
if (outside) { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
return; | ||
} | ||
|
||
if (e.type === "click") { | ||
props.node.handleClick(e); | ||
} | ||
}; | ||
|
||
if (isTitle || isSeparator) { | ||
return ( | ||
<div | ||
|
@@ -368,7 +400,8 @@ const Row = <T,>({ children, ...props }: RowProps<T>) => { | |
key={props.node.id} | ||
ref={props.innerRef} | ||
onFocus={(e) => e.stopPropagation()} | ||
onClick={props.node.handleClick} | ||
onMouseDown={handleRowMouseEvent} | ||
onClick={handleRowMouseEvent} | ||
onKeyDown={handleKeyDown} | ||
Comment on lines
+403
to
405
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find The root problem seems to have the children that is not the same height as the parent, on Docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or |
||
> | ||
<div className="c__tree-view--row-content">{children}</div> | ||
|
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.
I guess it is just for dev purpose, no?