Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(www): Fix sidebar expansion behavior #23325

Merged
merged 1 commit into from
Apr 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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