Replies: 1 comment 5 replies
-
I guess it may be possible by swizzling the tab component and detecting the platform in the useragent import React, { useState, useEffect } from 'react'
import TabItem from '@theme-original/TabItem'
const isMacintosh = () => navigator.userAgentData.platform === 'macOS'
const isWindows = () => navigator.userAgentData.platform === 'Windows'
const isLinux = () => navigator.userAgentData.platform === 'Linux'
export default function TabItemWrapper(props) {
const [defaultTab, setDefaultTab] = useState(null)
useEffect(() => {
if (isMacintosh()) setDefaultTab('apple')
else if (isWindows()) setDefaultTab('windows')
else if (isLinux()) setDefaultTab('linux')
}, [])
const isDefault = props.value === defaultTab
return <TabItem {...props} hidden={isDefault ? false : true} default={isDefault ? true : undefined} />
} And then default select the tab depending on the platform (no idea on how to do this) Edit: the default value seems a bit buggy in this implementation I don't know why |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the Install Guide page I use the
<Tabs>
component with 3 platform specific<TabItem>
(Windows/macOS/GNu/Linux).Everything is fine, the multiple
<Tabs groupId="operating-systems"> ... </Tabs>
are rendered correctly and the selection is synchronised to all instances.As a further improvement, I would like to automatically configure the default selection to match the platform the web page is accessed from.
Any idea how to do it? (Sorry, my experience with client side JS is poor)
Beta Was this translation helpful? Give feedback.
All reactions