mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-03 12:17:20 +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 {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
||||||
import {translate} from '@docusaurus/Translate';
|
import {translate} from '@docusaurus/Translate';
|
||||||
import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
|
import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
|
||||||
|
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
||||||
|
|
||||||
const getVersionMainDoc = (version: GlobalVersion) =>
|
const getVersionMainDoc = (version: GlobalVersion) =>
|
||||||
version.docs.find((doc) => doc.id === version.mainDocId)!;
|
version.docs.find((doc) => doc.id === version.mainDocId)!;
|
||||||
|
@ -36,7 +37,7 @@ export default function DocsVersionDropdownNavbarItem({
|
||||||
const {preferredVersion, savePreferredVersionName} =
|
const {preferredVersion, savePreferredVersionName} =
|
||||||
useDocsPreferredVersion(docsPluginId);
|
useDocsPreferredVersion(docsPluginId);
|
||||||
|
|
||||||
function getItems() {
|
function getItems(): LinkLikeNavbarItemProps[] {
|
||||||
const versionLinks = versions.map((version) => {
|
const versionLinks = versions.map((version) => {
|
||||||
// We try to link to the same doc, in another version
|
// We try to link to the same doc, in another version
|
||||||
// When not possible, fallback to the "main doc" of the 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
|
// Mobile dropdown is handled a bit differently
|
||||||
const dropdownLabel =
|
const dropdownLabel =
|
||||||
mobile && items
|
mobile && items.length > 1
|
||||||
? translate({
|
? translate({
|
||||||
id: 'theme.navbar.mobileVersionsDropdown.label',
|
id: 'theme.navbar.mobileVersionsDropdown.label',
|
||||||
message: 'Versions',
|
message: 'Versions',
|
||||||
|
@ -73,7 +74,9 @@ export default function DocsVersionDropdownNavbarItem({
|
||||||
})
|
})
|
||||||
: dropdownVersion.label;
|
: dropdownVersion.label;
|
||||||
const dropdownTo =
|
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
|
// 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'])
|
// If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue