Skip to content

Commit 29107d2

Browse files
committed
Regen docs and add controlled state warning
1 parent 5af3ce7 commit 29107d2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

docs/pages/api/tree-view.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
2828
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
2929
| <span class="prop-name">defaultCollapseIcon</span> | <span class="prop-type">node</span> | | The default icon used to collapse the node. |
3030
| <span class="prop-name">defaultEndIcon</span> | <span class="prop-type">node</span> | | The default icon displayed next to a end node. This is applied to all tree nodes and can be overridden by the TreeItem `icon` prop. |
31-
| <span class="prop-name">defaultExpanded</span> | <span class="prop-type">Array<string></span> | <span class="prop-default">[]</span> | Expanded node ids. |
31+
| <span class="prop-name">defaultExpanded</span> | <span class="prop-type">Array<string></span> | <span class="prop-default">[]</span> | Expanded node ids. (Uncontrolled) |
3232
| <span class="prop-name">defaultExpandIcon</span> | <span class="prop-type">node</span> | | The default icon used to expand the node. |
3333
| <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. |
34-
| <span class="prop-name">onNodeToggle</span> | <span class="prop-type">func</span> | | Callback fired when a `TreeItem` is expanded/collapsed.<br><br>**Signature:**<br>`function(nodeId: string, expanded: boolean) => void`<br>*nodeId:* The id of the toggled node.<br>*expanded:* The node status - If `true` the node was expanded. If `false` the node was collapsed. |
34+
| <span class="prop-name">expanded</span> | <span class="prop-type">Array<string></span> | | Expanded node ids. (Controlled) |
35+
| <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(nodeIds: array, expanded: boolean) => void`<br>*nodeIds:* The ids of the toggled nodes.<br>*expanded:* The nodes' status - If `true` the nodes were expanded. If `false` the node were collapsed. |
3536

3637
The `ref` is forwarded to the root element.
3738

packages/material-ui-lab/src/TreeView/TreeView.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,25 @@ const TreeView = React.forwardRef(function TreeView(props, ref) {
4444
const isTabable = id => tabable === id;
4545
const isFocused = id => focused === id;
4646

47+
if (process.env.NODE_ENV !== 'production') {
48+
// eslint-disable-next-line react-hooks/rules-of-hooks
49+
React.useEffect(() => {
50+
if (isControlled !== (expandedProp != null)) {
51+
console.error(
52+
[
53+
`Material-UI: A component is changing ${
54+
isControlled ? 'a ' : 'an un'
55+
}controlled Select to be ${isControlled ? 'un' : ''}controlled.`,
56+
'Elements should not switch from uncontrolled to controlled (or vice versa).',
57+
'Decide between using a controlled or uncontrolled Select ' +
58+
'element for the lifetime of the component.',
59+
'More info: https://fb.me/react-controlled-components',
60+
].join('\n'),
61+
);
62+
}
63+
}, [expandedProp, isControlled]);
64+
}
65+
4766
React.useEffect(() => {
4867
nodeMap.current = {};
4968
const childIds = React.Children.map(children, child => child.props.nodeId);

0 commit comments

Comments
 (0)