Skip to content

Commit

Permalink
fix(www): Fix sidebar expansion behavior (#23325)
Browse files Browse the repository at this point in the history
  • Loading branch information
tesseralis authored Apr 21, 2020
1 parent 5f1e42d commit 3c123c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions www/src/components/sidebar/__tests__/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ describe("sidebar", () => {

describe("initialization", () => {
it("opens sections with active items", () => {
// Render a page
renderSidebar("/plot-summary/").unmount()
// Render another page and make sure that its section is open even if
// a falsy value was stored in local storage
const { queryByText } = renderSidebar("/characters/jay-gatsby/")
expect(queryByText("Jay Gatsby")).toBeInTheDocument()
})
Expand Down
3 changes: 2 additions & 1 deletion www/src/components/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ function Sidebar({
)

// Merge hash in local storage and the derived hash from props
// so that all sections open in either hash are open
const initialHash = (() => {
const { openSectionHash = {} } = readLocalStorage(sidebarKey)
for (const [key, isOpen] of Object.entries(derivedHash)) {
openSectionHash[key] = openSectionHash[key] ?? isOpen
openSectionHash[key] = openSectionHash[key] || isOpen
}
return openSectionHash
})()
Expand Down

0 comments on commit 3c123c7

Please sign in to comment.