mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-02 11:47:23 +02:00
fix(theme-classic): fix mobile version dropdown label with only one version (#6314)
* fix(theme-classic): fix mobile version dropdown label with only one version * properly fix
This commit is contained in:
parent
ba352271e7
commit
a2d2324ca7
1 changed files with 6 additions and 3 deletions
|
@ -17,6 +17,7 @@ import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|||
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
||||
import {translate} from '@docusaurus/Translate';
|
||||
import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
|
||||
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
||||
|
||||
const getVersionMainDoc = (version: GlobalVersion) =>
|
||||
version.docs.find((doc) => doc.id === version.mainDocId)!;
|
||||
|
@ -36,7 +37,7 @@ export default function DocsVersionDropdownNavbarItem({
|
|||
const {preferredVersion, savePreferredVersionName} =
|
||||
useDocsPreferredVersion(docsPluginId);
|
||||
|
||||
function getItems() {
|
||||
function getItems(): LinkLikeNavbarItemProps[] {
|
||||
const versionLinks = versions.map((version) => {
|
||||
// We try to link to the same doc, in another version
|
||||
// When not possible, fallback to the "main doc" of the version
|
||||
|
@ -64,7 +65,7 @@ export default function DocsVersionDropdownNavbarItem({
|
|||
|
||||
// Mobile dropdown is handled a bit differently
|
||||
const dropdownLabel =
|
||||
mobile && items
|
||||
mobile && items.length > 1
|
||||
? translate({
|
||||
id: 'theme.navbar.mobileVersionsDropdown.label',
|
||||
message: 'Versions',
|
||||
|
@ -73,7 +74,9 @@ export default function DocsVersionDropdownNavbarItem({
|
|||
})
|
||||
: dropdownVersion.label;
|
||||
const dropdownTo =
|
||||
mobile && items ? undefined : getVersionMainDoc(dropdownVersion).path;
|
||||
mobile && items.length > 1
|
||||
? undefined
|
||||
: getVersionMainDoc(dropdownVersion).path;
|
||||
|
||||
// We don't want to render a version dropdown with 0 or 1 item
|
||||
// If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
|
||||
|
|
Loading…
Add table
Reference in a new issue