Skip to content

[Docs]: Add version selector to VersionBadge#1308

Open
modulareverything wants to merge 1 commit intodavidjerleke:masterfrom
modulareverything:feature/version-badge-dropdown
Open

[Docs]: Add version selector to VersionBadge#1308
modulareverything wants to merge 1 commit intodavidjerleke:masterfrom
modulareverything:feature/version-badge-dropdown

Conversation

@modulareverything
Copy link

Adds dropdown functionality to the VersionBadge, allowing the user to select between versions.

Uses DOCS_LATEST_VERSION, DOCS_VERSIONS from @/utils/global-data

I added a SUFFIX key to the VersionType for "latest" and "stable". This is optional and could be removed if it's gonna F with anything else on the site I'm unaware of, but it does give us an easy way of giving the user more context around the releases (v8 = "stable").

This is my first PR, so let me know if you'd like me to change anything here. Otherwise, it's pretty straightforward and follows a common pattern.

@davidjerleke davidjerleke changed the title Docs - Add version selector to VersionBadge [Docs]: Add version selector to VersionBadge Mar 16, 2026
@davidjerleke davidjerleke added documentation Improvements or additions to documentation labels Mar 16, 2026
@davidjerleke davidjerleke self-assigned this Mar 18, 2026
Copy link
Owner

@davidjerleke davidjerleke left a comment

Choose a reason for hiding this comment

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

Thanks a lot for your contribution @modulareverything — it's really appreciated, and contributions like this are much needed in this project 🙌.

I have a few minor comments and suggestions, but overall this is a great step forward.

One thing I’m not entirely sure about is whether using a <select> element for navigation is fully acceptable from an accessibility standpoint. That said, this is still a solid improvement since it allows users to easily switch between documentation versions, which wasn’t possible before.

Also, some pages won’t have a 1:1 mapping between versions and may result in a 404. For example, /docs/plugins/accessibility doesn’t exist in /docs/v8/plugins/accessibility since v8 doesn’t include that plugin. You can decide whether to handle that in this PR or leave it for a follow-up — either way works, as this is definitely a step in the right direction.

Again, thanks!

display: inline-flex;
padding: 0.2rem ${SPACINGS.THREE};
align-items: center;
padding: 0.6rem ${SPACINGS.THREE};
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
padding: 0.6rem ${SPACINGS.THREE};
padding: ${SPACINGS.ONE} ${SPACINGS.THREE};

const major = Number(event.target.value)
const nextPathname = `/${getVersionPathname(pathname, major)}`

if (nextPathname === pathname) return
Copy link
Owner

Choose a reason for hiding this comment

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

Let’s start loading the route here to maintain the strong INP score the website currently has 🙂:

Suggested change
if (nextPathname === pathname) return
if (nextPathname === pathname) return
dispatch(setRoutesLoading(true))

Comment on lines +58 to +59
const versionPrefix = major === DOCS_LATEST_VERSION.MAJOR ? [] : [`v${major}`]
return ['docs', ...versionPrefix, ...getDocsSubPath(pathname)].join('/')
Copy link
Owner

Choose a reason for hiding this comment

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

We could reuse existing helpers to achieve the same result—see prefixSlugWithDocs() and joinSlugs.

function getVersionPathname(pathname = '', major: number): string {
  const versionPrefix = major === DOCS_LATEST_VERSION.MAJOR ? '' : `v${major}`
  const versionAndSubPath =  joinSlugs(versionPrefix, ...getDocsSubPath(pathname))
  return prefixSlugWithDocs(versionAndSubPath)
}

Comment on lines +48 to +55
function getDocsSubPath(pathname = ''): string[] {
if (!pathname.startsWith('/docs')) return []
const [, ...docsSubPath] = pathname.split('/').filter(Boolean)

return DOCS_VERSION_SEGMENT_REGEX.test(docsSubPath[0] ?? '')
? docsSubPath.slice(1)
: docsSubPath
}
Copy link
Owner

Choose a reason for hiding this comment

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

An alternative approach is to use a regex like this. There’s no need to change it, though — feel free to choose whichever option you find more readable.

const DOCS_WITH_VERSION_REGEX = /^\/docs(?:\/v\d+)?/

function getDocsSubPath(pathname = ''): string[] {
  if (!pathname.startsWith('/docs')) return []
  return pathname
    .replace(DOCS_WITH_VERSION_REGEX, '')
    .split('/')
    .filter(Boolean)
}

@davidjerleke davidjerleke added the changes requested Changes needed for this to be approved label Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changes requested Changes needed for this to be approved documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants