diff --git a/docs/website/src/theme/Root.js b/docs/website/src/theme/Root.js index 5a177c42c6..fdb4786f51 100644 --- a/docs/website/src/theme/Root.js +++ b/docs/website/src/theme/Root.js @@ -1,8 +1,20 @@ import React, {useState, useEffect} from 'react'; import {useLocation} from '@docusaurus/router'; +import { useActiveDocContext } from '@docusaurus/plugin-content-docs/client'; // inject overlay content in root element export default function Root({children}) { + const { activeVersion } = useActiveDocContext(); + + useEffect(() => { + if (activeVersion) { + // Remove all version classes + document.body.className = document.body.className.replace(/\bversion-\S+/g, ''); + // Add the active version class + document.body.classList.add(`version-${activeVersion.name}`); + } + }, [activeVersion]); + return <>{children}; }