Skip to content
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

fix: hide indicator outside the droppable area (#477) #478

Merged
merged 2 commits into from
Aug 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ class Tree extends React.Component<TreeProps, TreeState> {

dragNode: NodeInstance;

currentMouseOverDroppableNodeKey = null;

listRef = React.createRef<NodeListRef>();

componentWillUnmount() {
Expand Down Expand Up @@ -445,9 +447,14 @@ class Tree extends React.Component<TreeProps, TreeState> {
onNodeDragEnter = (event: React.DragEvent<HTMLDivElement>, node: NodeInstance) => {
const { expandedKeys, keyEntities, dragChildrenKeys, flattenNodes, indent } = this.state;
const { onDragEnter, onExpand, allowDrop, direction } = this.props;
const { pos } = node.props;
const { pos, eventKey } = node.props;
const { dragNode } = this;

// record the key of node which is latest entered, used in dragleave event.
if (this.currentMouseOverDroppableNodeKey !== eventKey) {
this.currentMouseOverDroppableNodeKey = eventKey;
}

const {
dropPosition,
dropLevelOffset,
Expand Down Expand Up @@ -644,6 +651,24 @@ class Tree extends React.Component<TreeProps, TreeState> {
};

onNodeDragLeave: NodeDragEventHandler = (event, node) => {
// if it is outside the droppable area
// currentMouseOverDroppableNodeKey will be updated in dragenter event when into another droppable receiver.
if (
this.currentMouseOverDroppableNodeKey === node.props.eventKey &&
!event.currentTarget.contains(event.relatedTarget as Node)
) {
this.setState({
dropPosition: null,
dropLevelOffset: null,
dropTargetKey: null,
dropContainerKey: null,
dropTargetPos: null,
dropAllowed: false,
dragOverNodeKey: null,
});
this.currentMouseOverDroppableNodeKey = null;
}

const { onDragLeave } = this.props;

if (onDragLeave) {
Expand Down Expand Up @@ -738,6 +763,7 @@ class Tree extends React.Component<TreeProps, TreeState> {
});
}
this.dragStartMousePosition = null;
this.currentMouseOverDroppableNodeKey = null;
};

onNodeClick: NodeMouseEventHandler = (e, treeNode) => {
Expand Down