From bdbccaaff826d0378e3d1af4d5c1c4197dfcc9ac Mon Sep 17 00:00:00 2001 From: Cole Bemis Date: Thu, 10 Nov 2022 06:32:19 -0800 Subject: [PATCH] TreeView: Preserve expanded state of nested items (#2538) * Add failing test * Require id prop on tree items * Create expanded cache * Update expanded state cache * Remove console.log * Add comment about expanded cache * Update comment * Create sour-readers-rescue.md * Update src/TreeView/TreeView.tsx Co-authored-by: Josh Black * Fix lint errors Co-authored-by: Josh Black --- .changeset/sour-readers-rescue.md | 16 ++ docs/content/TreeView.mdx | 46 ++-- src/TreeView/TreeView.features.stories.tsx | 84 ++++--- src/TreeView/TreeView.stories.tsx | 8 +- src/TreeView/TreeView.test.tsx | 272 +++++++++++++-------- src/TreeView/TreeView.tsx | 79 +++--- src/hooks/useControllableState.ts | 2 +- 7 files changed, 310 insertions(+), 197 deletions(-) create mode 100644 .changeset/sour-readers-rescue.md diff --git a/.changeset/sour-readers-rescue.md b/.changeset/sour-readers-rescue.md new file mode 100644 index 00000000000..b70dcaf0f45 --- /dev/null +++ b/.changeset/sour-readers-rescue.md @@ -0,0 +1,16 @@ +--- +"@primer/react": patch +--- + +TreeView: Preserve expanded state of nested items when parent item is collapsed. + +**Breaking change** + +`TreeView.Item` and `TreeView.LinkItem` now require an `id` prop: + +```diff +- ... ++ ... +``` + +This is not in a major release because TreeView is still a `draft` component. diff --git a/docs/content/TreeView.mdx b/docs/content/TreeView.mdx index 16dd99d9221..f32b9ab1782 100644 --- a/docs/content/TreeView.mdx +++ b/docs/content/TreeView.mdx @@ -13,13 +13,13 @@ description: A hierarchical list of items where nested items can be expanded and