-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TreeView] Add disabled prop (#20133)
- Loading branch information
1 parent
de2af45
commit 08d7334
Showing
11 changed files
with
900 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
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'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import Switch from '@material-ui/core/Switch'; | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
root: { | ||
height: 270, | ||
flexGrow: 1, | ||
maxWidth: 400, | ||
}, | ||
actions: { | ||
marginBottom: theme.spacing(1), | ||
}, | ||
})); | ||
|
||
export default function DisabledTreeItems() { | ||
const classes = useStyles(); | ||
const [focusDisabledItems, setFocusDisabledItems] = React.useState(false); | ||
const handleToggle = (event) => { | ||
setFocusDisabledItems(event.target.checked); | ||
}; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<div className={classes.actions}> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={focusDisabledItems} | ||
onChange={handleToggle} | ||
name="focusDisabledItems" | ||
/> | ||
} | ||
label="Focus disabled items" | ||
/> | ||
</div> | ||
<TreeView | ||
aria-label="disabled items" | ||
defaultCollapseIcon={<ExpandMoreIcon />} | ||
defaultExpandIcon={<ChevronRightIcon />} | ||
disabledItemsFocusable={focusDisabledItems} | ||
multiSelect | ||
> | ||
<TreeItem nodeId="1" label="One"> | ||
<TreeItem nodeId="2" label="Two" /> | ||
<TreeItem nodeId="3" label="Three" /> | ||
<TreeItem nodeId="4" label="Four" /> | ||
</TreeItem> | ||
<TreeItem nodeId="5" label="Five" disabled> | ||
<TreeItem nodeId="6" label="Six" /> | ||
</TreeItem> | ||
<TreeItem nodeId="7" label="Seven"> | ||
<TreeItem nodeId="8" label="Eight" /> | ||
<TreeItem nodeId="9" label="Nine"> | ||
<TreeItem nodeId="10" label="Ten"> | ||
<TreeItem nodeId="11" label="Eleven" /> | ||
<TreeItem nodeId="12" label="Twelve" /> | ||
</TreeItem> | ||
</TreeItem> | ||
</TreeItem> | ||
</TreeView> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
import { createStyles, 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'; | ||
import FormControlLabel from '@material-ui/core/FormControlLabel'; | ||
import Switch from '@material-ui/core/Switch'; | ||
|
||
const useStyles = makeStyles((theme) => | ||
createStyles({ | ||
root: { | ||
height: 270, | ||
flexGrow: 1, | ||
maxWidth: 400, | ||
}, | ||
actions: { | ||
marginBottom: theme.spacing(1), | ||
}, | ||
}), | ||
); | ||
|
||
export default function DisabledTreeItems() { | ||
const classes = useStyles(); | ||
const [focusDisabledItems, setFocusDisabledItems] = React.useState(false); | ||
const handleToggle = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setFocusDisabledItems(event.target.checked); | ||
}; | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<div className={classes.actions}> | ||
<FormControlLabel | ||
control={ | ||
<Switch | ||
checked={focusDisabledItems} | ||
onChange={handleToggle} | ||
name="focusDisabledItems" | ||
/> | ||
} | ||
label="Focus disabled items" | ||
/> | ||
</div> | ||
<TreeView | ||
aria-label="disabled items" | ||
defaultCollapseIcon={<ExpandMoreIcon />} | ||
defaultExpandIcon={<ChevronRightIcon />} | ||
disabledItemsFocusable={focusDisabledItems} | ||
multiSelect | ||
> | ||
<TreeItem nodeId="1" label="One"> | ||
<TreeItem nodeId="2" label="Two" /> | ||
<TreeItem nodeId="3" label="Three" /> | ||
<TreeItem nodeId="4" label="Four" /> | ||
</TreeItem> | ||
<TreeItem nodeId="5" label="Five" disabled> | ||
<TreeItem nodeId="6" label="Six" /> | ||
</TreeItem> | ||
<TreeItem nodeId="7" label="Seven"> | ||
<TreeItem nodeId="8" label="Eight" /> | ||
<TreeItem nodeId="9" label="Nine"> | ||
<TreeItem nodeId="10" label="Ten"> | ||
<TreeItem nodeId="11" label="Eleven" /> | ||
<TreeItem nodeId="12" label="Twelve" /> | ||
</TreeItem> | ||
</TreeItem> | ||
</TreeItem> | ||
</TreeView> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.