You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adaptive Navbar docsVersionDropdown for multi-SDK doc websites #3930
closed: duplicateThis issue or pull request already exists in another issue or pull requestfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.
If a Docusaurus project has documentation for 2 or more SDKs (which is supported in the latest releases thanks to multi-doc-plugin support - see #2528 (comment)), the Navbar docsVersionDropdown should have the ability to display the versions of the SDK page the user is currently in.
Suppose the user is in the page of Android SDK Docs. The Navbar should display versions of Android SDK. If they go to iOS docs, the navbar should now display versions of iOS SDK.
We are a company that has multiple tiers of SDKs that has different versioning timelines.
Pitch
Having a multi-doc website with a navbar version dropdown that doesn't change according to the SDK you select confuses many people.
The structure of Navbar dropdown right now: {type: "docsVersionDropdown", docsPluginId: "ios"}
We can have something similar to: {type: "docsVersionDropdown", defaultDocsPluginId: "ios", dynamicVersioningChange: true} for enabling dynamic versioning change according to the SDK docs the user is currently viewing. The defaultDocsPluginId can be used for knowing what plugin version to display in non-docs pages like Home, Blogs etc.
Future Scope
An 'override' parameter in each plugin for choosing which pluginId versioning has to be displayed in the navbar.
Reacted by Kashif Saadat, Volodymyr Smolianinov, Stan Girard, Nikita Gaer, Vir Desai, Miguel, Kyung Lee, Ben Perlmutter, Antony Onipko and Zena
What about adding multiInstance: true in config so that it adapts?
The docsPluginId option can serve as the default instance if multi-instance support is enabled?
That makes sense. However, I feel the name docsPluginId alone does not explain how it behaves when it is in multiInstance. A better name like defaultDocsPluginId would give an insight into how it behaves in both cases.
Currently could be solved using custom NavbarItem (src/theme/NavbarItem.js)
importReactfrom'react';importOriginalNavBarItemfrom'@theme-original/NavbarItem';import{useLocation}from'@docusaurus/router';exportdefaultfunctionNavbarItem(props){const{ docsPluginId, type }=propsconst{ pathname }=useLocation()if(type==='docsVersionDropdown'&&pathname.search(newRegExp(`^/${docsPluginId}/`,'g'))===-1){returnnull}return(<><OriginalNavBarItem{...props}/></>);}
Hi @ngaer, thank you so much for the workaround! 💐 It really helped.
One question is that after applying the workaround, the docsVersionDropdown of doc instances that are versioned also disappeared. How can I get them out, and only hide the docsVersionDropdown for the doc instances that are not versioned?
You have to create the if condition that makes sense for your project. The above may work for @ngaer but won't work for all use-cases, and you have to adapt it. In fact, it is likely to not work for many projects because it assumes the pathname contains the docsPluginId, which is generally false.
There is an undocumented hook that you can use to know which plugin created the current route:
Thank you slorber! You are right about creating the if condition that makes sense for my project. I adjusted the condition as follows and it is working well:
Currently could be solved using custom NavbarItem (src/theme/NavbarItem.js)
importReactfrom'react';importOriginalNavBarItemfrom'@theme-original/NavbarItem';import{useLocation}from'@docusaurus/router';exportdefaultfunctionNavbarItem(props){const{ docsPluginId, type }=propsconst{ pathname }=useLocation()if(type==='docsVersionDropdown'&&pathname.search(newRegExp(`^/${docsPluginId}/`,'g'))===-1){returnnull}return(<><OriginalNavBarItem{...props}/></>);}
Hi @ngaer / @randomJoe211 / @slorber , I seem to have a similar requirement. The only difference is I want the Navbar dropdown items to change with the versions. I was wondering if you could help me with the logic here?
I want to customize my Navbar in such a way that, say when versions 1.2.0 and below are viewed, only Dropdown A should be visible. When versions 1.3.0 and above are viewed, Dropdown B or more must be visible.
For clear understanding:
Navbar when browsing version 1.3.0 and above:
@aneesha178 track #4389 for an upcoming official solution to solve this problem through config files.
Until then I suggest taking a look at CSS classes that we add to the top-level <html> element of your Docusaurus site, those classes should help you create CSS selectors that hide/show relevant items depending on context.
You'd have to assign a custom class like .myNavbarItem to the element you want to hide for v2.2.0, this can be provided through navbar item themeConfig className
closed: duplicateThis issue or pull request already exists in another issue or pull requestfeatureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Activity
sidvenu commentedon Dec 17, 2020
@slorber as discussed in Discord. What do you think of the proposal? Would love to start work on this if this is approved.
slorber commentedon Dec 18, 2020
What about adding
multiInstance: truein config so that it adapts?The
docsPluginId optioncan serve as the default instance if multi-instance support is enabled?sidvenu commentedon Dec 18, 2020
That makes sense. However, I feel the name
docsPluginIdalone does not explain how it behaves when it is inmultiInstance. A better name likedefaultDocsPluginIdwould give an insight into how it behaves in both cases.StanGirard commentedon Mar 11, 2021
@sidvenu Have you found any workaround for now to get it working?
slorber commentedon Mar 11, 2021
if anyone has an existing site online with the UX problem, that would likely help to understand better what a solution could look like
slorber commentedon Mar 12, 2021
FYI some idea I have that could also solve this issue: #4389 (comment)
StanGirard commentedon Mar 12, 2021
@slorber That is exactly what we are looking for. Thanks for being so pro-active.
ngaer commentedon Apr 14, 2021
Currently could be solved using custom NavbarItem (
src/theme/NavbarItem.js)slorber commentedon Apr 14, 2021
Thanks @ngaer , looks like a nice temporary workaround
iamayushdas commentedon May 18, 2021
can you help me in using this
Josh-Cena commentedon Oct 30, 2021
Closing in favor of #4389.
randomJoe211 commentedon Oct 17, 2022
Hi @ngaer, thank you so much for the workaround! 💐 It really helped.
One question is that after applying the workaround, the docsVersionDropdown of doc instances that are versioned also disappeared. How can I get them out, and only hide the docsVersionDropdown for the doc instances that are not versioned?
slorber commentedon Oct 19, 2022
@randomJoe211 it's your responsability to implement the logic that decides if something is displayed or not, we can't really help you here
You have to create the if condition that makes sense for your project. The above may work for @ngaer but won't work for all use-cases, and you have to adapt it. In fact, it is likely to not work for many projects because it assumes the pathname contains the docsPluginId, which is generally false.
There is an undocumented hook that you can use to know which plugin created the current route:
randomJoe211 commentedon Oct 20, 2022
Thank you slorber! You are right about creating the if condition that makes sense for my project. I adjusted the condition as follows and it is working well:
As a workaround, this is good enough. Still, I look forward to a standard feature to resolve this issue.
aneesha178 commentedon Jan 7, 2023
Hi @ngaer / @randomJoe211 / @slorber , I seem to have a similar requirement. The only difference is I want the Navbar dropdown items to change with the versions. I was wondering if you could help me with the logic here?
I want to customize my Navbar in such a way that, say when versions 1.2.0 and below are viewed, only Dropdown A should be visible. When versions 1.3.0 and above are viewed, Dropdown B or more must be visible.
For clear understanding:
Navbar when browsing version 1.3.0 and above:
Navbar when browsing version 1.2.0 and below:
slorber commentedon Jan 19, 2023
@aneesha178 track #4389 for an upcoming official solution to solve this problem through config files.
Until then I suggest taking a look at CSS classes that we add to the top-level
<html>element of your Docusaurus site, those classes should help you create CSS selectors that hide/show relevant items depending on context.<html class="plugin-docs plugin-id-default docs-version-2.2.0">You could for example create selectors like this:
You'd have to assign a custom class like
.myNavbarItemto the element you want to hide for v2.2.0, this can be provided through navbar item themeConfig className