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

feat(v2): add option to toggle sidebar category open by default #2613

Merged
merged 7 commits into from
Apr 22, 2020

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Apr 15, 2020

This PR adds the ability to toggle sidebar categories open by default.

Changes

  • update sidebar category to take collapsed prop
  • add extra sidebars collapsed test
  • only mutate item.collapsed if necessary
  • update docs for SidebarItemCategory

Motivation

Fixes #2354

Have you read the Contributing Guidelines on pull requests?

Yes.

Test Plan

I wrote extensive notes on the issue: #2354

Here's how I tested my changes:

  1. Built project: yarn build
  2. Published to verdaccio locally: yarn lerna publish --registry http://localhost:4873 --no-git-tag-version
  3. Created a new website:
# set the registry to verdaccio
npm set registry http://localhost:4873/
# install @docusaurus/init globally
npm i -g @docusaurus/init
# run the binary from the location directly
/Users/jprevite/.nvm/versions/node/v10.15.1/lib/node_modules/@docusaurus/init/bin/index.js init test-joe
  1. Modified the sidebars.js file:
module.exports = {
  someSidebar: 
     [
      {
        "type": "category",
        "label": "Introduction",
        "items": ["doc1"],
        "collapsed": true
      },
      {
        "type": "category",
        "label": "Powering MDX",
        "items": ["doc2"],
        "collapsed": false
      }
    ]
  }
  1. Tested if changes worked (and they did 🎉). You can tell because "Powering MDX" is not collapsed (because it's set to false in the sidebars.js file.
    image

Screenshots

Here are a few other screenshots of it in action:

Before

This is what happens before I made any changes. (note: I load the page, "Powering MDX" is collapsed).

2020-04-15 13 27 25

After

I made the change and now it loads and is expanded (not collapsed) like I want!

2020-04-15 14 02 17

And, if I'm on the "Powering MDX", it should be expanded (because it's the current page), which still works as expected.

2020-04-15 14 02 53

Related PRs

(If this PR adds or changes functionality, please take some time to update the docs at https://github.com/facebook/docusaurus, and link to your PR here.)

@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 15, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Apr 15, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 6c6f420

https://deploy-preview-2613--docusaurus-2.netlify.app

@jsjoeio jsjoeio self-assigned this Apr 15, 2020
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 15, 2020

The following tests are failing:

  • docsVersion
    • first time versioning
    • not the first time versioning
  • loadSidebars
    • sidebars with known sidebar item type
    • sidebars shortand and longform lead to exact same sidebar
    • sidebars link
  • versioned website
    • content

Any guidance on how to fix these would be awesome!

@jsjoeio jsjoeio marked this pull request as ready for review April 15, 2020 23:13
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 15, 2020

Additional suggestions (out of the scope of this work):

  • we should link to the local-third-party-project-testing.md in the CONTRIBUTING.md
  • the swizzle section of the docs should have an example:
yarn swizzle @docusaurus/theme-classic DocSidebar

@lex111
Copy link
Contributor

lex111 commented Apr 17, 2020

@jsjoeio if I understand correctly, you just need to update snapshots, run yarn test -u.

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 20, 2020

if I understand correctly, you just need to update snapshots, run yarn test -u.

That worked for the snapshot tests! Now I just have to fix the actual test that I broke 😂 Thank you @lex111 🎉

@lex111 lex111 added this to the v2.0.0-alpha.51 milestone Apr 21, 2020
Copy link
Contributor

@yangshun yangshun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Joe!

@yangshun yangshun added the pr: new feature This PR adds a new API or behavior. label Apr 22, 2020
@yangshun
Copy link
Contributor

@jsjoeio We should also update the docs to tell people about this cool new feature :)

@yangshun yangshun changed the title feat(sidebar): add option to toggle sidebar category open by default feat(v2): add option to toggle sidebar category open by default Apr 22, 2020
@yangshun yangshun merged commit 1863a3c into master Apr 22, 2020
@yangshun yangshun deleted the jsjoeio/toggle-sidebar-open-default branch April 22, 2020 12:31
lex111 added a commit that referenced this pull request Apr 22, 2020
lex111 added a commit that referenced this pull request Apr 22, 2020
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 22, 2020

We should also update the docs to tell people about this cool new feature :)

@yangshun Yes! Agreed :) I updated the example here in this PR.

I'll open a separate PR and add a short paragraph to that section of the docs!

@yangshun
Copy link
Contributor

@jsjoeio seems like there was a bug, found by @lex111. We have to resubmit this PR.

@jsjoeio jsjoeio restored the jsjoeio/toggle-sidebar-open-default branch April 23, 2020 23:37
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 23, 2020

@yangshun Oh no! Okay. Do you want me to do that? (i.e. open a new PR with this work?)

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Apr 23, 2020

@yangshun actually, I'd like to propose moving this conversation to #2354 so it's easier to keep track of

@lex111 lex111 removed the pr: new feature This PR adds a new API or behavior. label Apr 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v2] Option to toggle docs category open by default
5 participants