Skip to content

Commit

Permalink
docs(treeview): clarify state props documentation (#15437)
Browse files Browse the repository at this point in the history
* docs(treenode): clarify props.active and props.selected

* docs(treenode): document props.id

* test(treenode): update api snapshot
  • Loading branch information
janhassel authored Jan 15, 2024
1 parent 16459b7 commit f9adf14
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9126,6 +9126,9 @@ Map {
"disabled": Object {
"type": "bool",
},
"id": Object {
"type": "string",
},
"isExpanded": Object {
"type": "bool",
},
Expand Down Expand Up @@ -9210,6 +9213,9 @@ Map {
"disabled": Object {
"type": "bool",
},
"id": Object {
"type": "string",
},
"isExpanded": Object {
"type": "bool",
},
Expand Down
15 changes: 12 additions & 3 deletions packages/react/src/components/TreeView/TreeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const TreeNode = React.forwardRef(
className,
depth,
disabled,
id: nodeId,
isExpanded,
label,
onNodeFocusEvent,
Expand All @@ -34,7 +35,7 @@ const TreeNode = React.forwardRef(
},
ref
) => {
const { current: id } = useRef(rest.id || uniqueId());
const { current: id } = useRef(nodeId || uniqueId());
const [expanded, setExpanded] = useState(isExpanded);
const currentNode = useRef(null);
const currentNodeLabel = useRef(null);
Expand Down Expand Up @@ -234,7 +235,8 @@ const TreeNode = React.forwardRef(

TreeNode.propTypes = {
/**
* The value of the active node in the tree
* **Note:** this is controlled by the parent TreeView component, do not set manually.
* The ID of the active node in the tree
*/
active: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

Expand All @@ -249,7 +251,8 @@ TreeNode.propTypes = {
className: PropTypes.string,

/**
* TreeNode depth to determine spacing, automatically calculated by default
* * **Note:** this is controlled by the parent TreeView component, do not set manually.
* TreeNode depth to determine spacing
*/
depth: PropTypes.number,

Expand All @@ -258,6 +261,11 @@ TreeNode.propTypes = {
*/
disabled: PropTypes.bool,

/**
* Specify the TreeNode's ID. Must be unique in the DOM and is used for props.active and props.selected
*/
id: PropTypes.string,

/**
* Specify if the TreeNode is expanded (only applicable to parent nodes)
*/
Expand Down Expand Up @@ -295,6 +303,7 @@ TreeNode.propTypes = {
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),

/**
* **Note:** this is controlled by the parent TreeView component, do not set manually.
* Array containing all selected node IDs in the tree
*/
selected: PropTypes.arrayOf(
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/TreeView/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export default function TreeView({

TreeView.propTypes = {
/**
* Mark the active node in the tree, represented by its value
* Mark the active node in the tree, represented by its ID
*/
active: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

Expand Down

0 comments on commit f9adf14

Please sign in to comment.