Skip to content

Commit 7c56f35

Browse files
authored
Merge pull request #6 from fritz-c/fix-canDrag
Fix canDrag
2 parents e658c70 + b096d68 commit 7c56f35

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

demo/app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class App extends Component {
2929
{
3030
title: 'tmp',
3131
isDirectory: true,
32-
children: [{ title: '12214124-log' }],
32+
children: [
33+
{ title: '12214124-log' },
34+
{ title: 'drag-disabled-file', dragDisabled: true },
35+
],
3336
},
3437
{
3538
title: 'build',
@@ -174,6 +177,7 @@ class App extends Component {
174177
searchFocusIndex:
175178
matches.length > 0 ? searchFocusIndex % matches.length : 0,
176179
})}
180+
canDrag={({ node }) => !node.dragDisabled}
177181
canDrop={({ nextParent }) => !nextParent || nextParent.isDirectory}
178182
generateNodeProps={rowInfo => ({
179183
icons: rowInfo.node.isDirectory

node-content-renderer.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class FileThemeNodeContentRenderer extends Component {
9090
}
9191
});
9292

93-
return connectDragSource(
93+
const nodeContent = (
9494
<div style={{ height: '100%' }} {...otherProps}>
9595
{toggleChildrenVisibility &&
9696
node.children &&
@@ -113,7 +113,12 @@ class FileThemeNodeContentRenderer extends Component {
113113
/>
114114
)}
115115

116-
<div className={styles.rowWrapper}>
116+
<div
117+
className={
118+
styles.rowWrapper +
119+
(!canDrag ? ` ${styles.rowWrapperDragDisabled}` : '')
120+
}
121+
>
117122
{/* Set the row preview to be used during drag and drop */}
118123
{connectDragPreview(
119124
<div style={{ display: 'flex' }}>
@@ -177,9 +182,12 @@ class FileThemeNodeContentRenderer extends Component {
177182
</div>
178183
)}
179184
</div>
180-
</div>,
181-
{ dropEffect: 'copy' }
185+
</div>
182186
);
187+
188+
return canDrag
189+
? connectDragSource(nodeContent, { dropEffect: 'copy' })
190+
: nodeContent;
183191
}
184192
}
185193

node-content-renderer.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
}
1313
}
1414

15+
.rowWrapperDragDisabled {
16+
cursor: default;
17+
}
18+
1519
.row {
1620
height: 100%;
1721
white-space: nowrap;

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"enzyme-adapter-react-16": "^1.0.1",
7070
"eslint": "^4.10.0",
7171
"eslint-config-airbnb": "^16.0.0",
72-
"eslint-config-prettier": "^2.6.0",
72+
"eslint-config-prettier": "^2.7.0",
7373
"eslint-loader": "^1.9.0",
7474
"eslint-plugin-import": "^2.8.0",
7575
"eslint-plugin-jsx-a11y": "^6.0.2",

0 commit comments

Comments
 (0)