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

[Treeview] Add node selection support #18357

Merged
merged 58 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
8c9334f
Intial
joshwooding Nov 13, 2019
b773431
Add typescript demo and minor changes
joshwooding Nov 13, 2019
25acc93
Prettier and selection logic
joshwooding Nov 13, 2019
4146414
docs:api
joshwooding Nov 13, 2019
0acc923
Lint fix
joshwooding Nov 13, 2019
c2577b3
Start of logic for range selection
joshwooding Nov 17, 2019
1d941f3
big brain time?
joshwooding Nov 18, 2019
7f95a92
Add keyboard control for selection
joshwooding Nov 19, 2019
d80da42
Only handle most key events when in multiSelect mode
joshwooding Nov 19, 2019
ca250cd
Olivier comment about range select behaviour
joshwooding Nov 20, 2019
eb94b63
Update docs/src/pages/components/tree-view/tree-view.md
joshwooding Nov 22, 2019
a10cf71
code review changes and add select state warning
joshwooding Nov 24, 2019
36e24d6
Merge branch 'tree-view-selection' of github.com:joshwooding/material…
joshwooding Nov 24, 2019
0915b61
prettier
joshwooding Nov 24, 2019
299d6a1
Add a space?
joshwooding Nov 24, 2019
1b3f9a9
Add test
joshwooding Dec 1, 2019
d61b9d8
Make icon smaller
joshwooding Dec 1, 2019
966b304
Merge branch 'master' into tree-view-selection
joshwooding Dec 1, 2019
61f3a37
docs:api
joshwooding Dec 1, 2019
45b07a5
Fix styling and demos
joshwooding Dec 1, 2019
30f035c
Exclude icon from selection
joshwooding Dec 1, 2019
aeb123a
Demo fix and ignore keyboard events if not on item
joshwooding Dec 1, 2019
1371206
Merge branch 'master' into tree-view-selection
joshwooding Dec 27, 2019
c11b5eb
Olivier comments
joshwooding Dec 27, 2019
1959627
demos
joshwooding Dec 27, 2019
bef084c
typo
joshwooding Dec 27, 2019
98864fd
Merge branch 'master' into tree-view-selection
joshwooding Jan 28, 2020
8743bda
prettier
joshwooding Jan 29, 2020
f915592
Add propHint to useControlled hook
joshwooding Jan 29, 2020
eedab96
Use propHint in TreeView
joshwooding Jan 29, 2020
f9afb75
Update TreeView tests and add better prop descriptions
joshwooding Jan 29, 2020
96de075
Add single selection tests and multi selection multiple mode tests
joshwooding Jan 30, 2020
6b87ba8
docs:api
joshwooding Jan 30, 2020
2fe2113
Why is TypeScript so hard
joshwooding Jan 31, 2020
f4e97e5
Finish test and fix selection logic
joshwooding Feb 1, 2020
cb6b000
Remove propHint
joshwooding Feb 2, 2020
acd4c29
Fix tests and run prettier
joshwooding Feb 2, 2020
4857bb2
Fix range selection logic with arrow keys. Add breaking test
joshwooding Feb 3, 2020
d25eb24
eps1lon codereview test changes
joshwooding Feb 13, 2020
fe071cf
Remove extra set state call
joshwooding Feb 15, 2020
8f18ef0
Change useControlled to always set state so TreeView can use callback…
joshwooding Feb 15, 2020
3a40b12
Play around with overlay
joshwooding Feb 15, 2020
d7ebe1e
Prettier
joshwooding Feb 15, 2020
3678e95
Revert changes
joshwooding Feb 15, 2020
774a98e
Play around some more with overlays
joshwooding Feb 15, 2020
2be953e
Merge branch 'master' into tree-view-selection
joshwooding Feb 15, 2020
3500845
proptypes
joshwooding Feb 15, 2020
5bbb10b
docs:api
joshwooding Feb 15, 2020
cacdb78
Re-add re-render
joshwooding Feb 15, 2020
071e2dc
Add re-render back
joshwooding Feb 15, 2020
36411d1
Move setChildrenCalculated
joshwooding Feb 15, 2020
423199b
Use backgroundColour instead of overlay
joshwooding Feb 18, 2020
aabf1d6
api:docs
joshwooding Feb 18, 2020
b54d059
New selection logic
joshwooding Feb 23, 2020
da9e659
Prettier
joshwooding Feb 25, 2020
059437e
Add range selection invalidation and fix bug where pressing up multip…
joshwooding Feb 25, 2020
ba8697c
prettier
joshwooding Feb 25, 2020
25ae073
proptypes
joshwooding Feb 25, 2020
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
1 change: 1 addition & 0 deletions docs/pages/api/tree-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Any other props supplied will be provided to the root element (native element).
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiTreeItem-root</span> | Styles applied to the root element.
| <span class="prop-name">expanded</span> | <span class="prop-name">.Mui-expanded</span> | Pseudo-class applied to the root element when expanded.
| <span class="prop-name">selected</span> | <span class="prop-name">.Mui-selected</span> | Pseudo-class applied to the root element when selected.
| <span class="prop-name">group</span> | <span class="prop-name">.MuiTreeItem-group</span> | Styles applied to the `role="group"` element.
| <span class="prop-name">content</span> | <span class="prop-name">.MuiTreeItem-content</span> | Styles applied to the tree node content.
| <span class="prop-name">iconContainer</span> | <span class="prop-name">.MuiTreeItem-iconContainer</span> | Styles applied to the tree node icon and collapse/expand icon.
Expand Down
5 changes: 5 additions & 0 deletions docs/pages/api/tree-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name">defaultExpanded</span> | <span class="prop-type">Array<string></span> | <span class="prop-default">[]</span> | Expanded node ids. (Uncontrolled) |
| <span class="prop-name">defaultExpandIcon</span> | <span class="prop-type">node</span> | | The default icon used to expand the node. |
| <span class="prop-name">defaultParentIcon</span> | <span class="prop-type">node</span> | | The default icon displayed next to a parent node. This is applied to all parent nodes and can be overridden by the TreeItem `icon` prop. |
| <span class="prop-name">defaultSelected</span> | <span class="prop-type">Array<string></span> | <span class="prop-default">[]</span> | Selected node ids. (Uncontrolled) |
| <span class="prop-name">disableSelection</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true` selection is disabled. |
| <span class="prop-name">expanded</span> | <span class="prop-type">Array<string></span> | | Expanded node ids. (Controlled) |
| <span class="prop-name">multiSelect</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If true `ctrl` and `shift` will trigger multiselect. |
| <span class="prop-name">onNodeSelect</span> | <span class="prop-type">func</span> | | Callback fired when tree items are selected/unselected.<br><br>**Signature:**<br>`function(event: object, nodeIds: array) => void`<br>*event:* The event source of the callback<br>*nodeIds:* The ids of the selected nodes. |
| <span class="prop-name">onNodeToggle</span> | <span class="prop-type">func</span> | | Callback fired when tree items are expanded/collapsed.<br><br>**Signature:**<br>`function(event: object, nodeIds: array) => void`<br>*event:* The event source of the callback<br>*nodeIds:* The ids of the expanded nodes. |
| <span class="prop-name">selected</span> | <span class="prop-type">Array<string></span> | | Selected node ids. (Controlled) |

The `ref` is forwarded to the root element.

Expand Down
41 changes: 41 additions & 0 deletions docs/src/pages/components/tree-view/MultiSelectTreeView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import TreeView from '@material-ui/lab/TreeView';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import TreeItem from '@material-ui/lab/TreeItem';

const useStyles = makeStyles({
root: {
height: 216,
flexGrow: 1,
maxWidth: 400,
},
});

export default function FileSystemNavigator() {
joshwooding marked this conversation as resolved.
Show resolved Hide resolved
const classes = useStyles();

return (
<TreeView
className={classes.root}
defaultCollapseIcon={<ExpandMoreIcon />}
defaultExpandIcon={<ChevronRightIcon />}
multiSelect
>
<TreeItem nodeId="1" label="Applications">
<TreeItem nodeId="2" label="Calendar" />
<TreeItem nodeId="3" label="Chrome" />
<TreeItem nodeId="4" label="Webstorm" />
</TreeItem>
<TreeItem nodeId="5" label="Documents">
<TreeItem nodeId="6" label="Material-UI">
<TreeItem nodeId="7" label="src">
<TreeItem nodeId="8" label="index.js" />
<TreeItem nodeId="9" label="tree-view.js" />
</TreeItem>
</TreeItem>
</TreeItem>
</TreeView>
);
}
41 changes: 41 additions & 0 deletions docs/src/pages/components/tree-view/MultiSelectTreeView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import TreeView from '@material-ui/lab/TreeView';
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
import TreeItem from '@material-ui/lab/TreeItem';

const useStyles = makeStyles({
root: {
height: 216,
flexGrow: 1,
maxWidth: 400,
},
});

export default function FileSystemNavigator() {
const classes = useStyles();

return (
<TreeView
className={classes.root}
defaultCollapseIcon={<ExpandMoreIcon />}
defaultExpandIcon={<ChevronRightIcon />}
multiSelect
>
<TreeItem nodeId="1" label="Applications">
<TreeItem nodeId="2" label="Calendar" />
<TreeItem nodeId="3" label="Chrome" />
<TreeItem nodeId="4" label="Webstorm" />
</TreeItem>
<TreeItem nodeId="5" label="Documents">
<TreeItem nodeId="6" label="Material-UI">
<TreeItem nodeId="7" label="src">
<TreeItem nodeId="8" label="index.js" />
<TreeItem nodeId="9" label="tree-view.js" />
</TreeItem>
</TreeItem>
</TreeItem>
</TreeView>
);
}
6 changes: 6 additions & 0 deletions docs/src/pages/components/tree-view/tree-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Tree views can be used to represent a file system navigator displaying folders a

{{"demo": "pages/components/tree-view/FileSystemNavigator.js"}}

## Multi Selection
joshwooding marked this conversation as resolved.
Show resolved Hide resolved

Tree views also support multi selection.

{{"demo": "pages/components/tree-view/MultiSelectTreeView.js"}}

## Customized tree view

### Custom icons, border and animation
Expand Down
Loading