forked from carbon-design-system/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(treeview): add experimental controllable API (carbon-design-syst…
…em#15397) Co-authored-by: Andrea N. Cardona <[email protected]>
- Loading branch information
1 parent
ee60555
commit b6710e7
Showing
8 changed files
with
410 additions
and
21 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
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
33 changes: 33 additions & 0 deletions
33
packages/react/src/components/TreeView/TreeView.featureflag.mdx
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,33 @@ | ||
# TreeView controllable API | ||
|
||
The new controllable API of TreeView allows you to synchronize the state of `selected` and `active` with your application. | ||
|
||
You can opt-in to this by enabling the `enable-treeview-controllable` feature flag. This changes the following behaviour: | ||
|
||
- `TreeView` | ||
- `props.onActivate` will be called with a node's ID whenever it is activated. | ||
- The signature of `props.onSelect` changes from `(event, selectedIDs)` to `(selectedIDs)`. | ||
- Whenever you update `props.selected` or `props.active`, the internal state will be updated accordingly and the component re-renders. | ||
- `TreeNode` | ||
- The signature of `props.onToggle` changes from `(event, { id, isExpanded, label, value })` to `(isExpanded)`. | ||
- `props.defaultIsExpanded` is added to allow for a default state in uncontrolled mode. | ||
|
||
## Example | ||
|
||
```jsx | ||
function SynchronizedTreeView() { | ||
const [selected, setSelected] = useState([]); | ||
const [active, setActive] = useState(null); | ||
|
||
return ( | ||
<TreeView | ||
selected={selected} | ||
onSelect={setSelected} | ||
active={active} | ||
onActivate={setActive} | ||
> | ||
... | ||
</TreeView> | ||
); | ||
} | ||
``` |
Oops, something went wrong.