From fd659050ab464285914585c29f93fbbfdaf1d651 Mon Sep 17 00:00:00 2001 From: Kyle Suss Date: Mon, 3 Aug 2020 09:40:15 -0600 Subject: [PATCH] Pass top level menu state to consumers of the TOC component --- src/components/table-of-contents/TableOfContents.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/table-of-contents/TableOfContents.js b/src/components/table-of-contents/TableOfContents.js index 19ad5a04..45c395f9 100644 --- a/src/components/table-of-contents/TableOfContents.js +++ b/src/components/table-of-contents/TableOfContents.js @@ -127,8 +127,18 @@ export function TableOfContents({ children, currentPath, items, ...rest }) { /> ); + // Top level menu state is used to control expand/collapse buttons in consumers + const allTopLevelMenusAreOpen = itemsWithUIState.every( + (item) => item.type === ITEM_TYPES.MENU && item.isOpen + ); + return typeof children === 'function' - ? children({ menu: tableOfContentsMenu, toggleAllOpen, toggleAllClosed }) + ? children({ + menu: tableOfContentsMenu, + allTopLevelMenusAreOpen, + toggleAllOpen, + toggleAllClosed, + }) : tableOfContentsMenu; }