docs: fix search bar not focused when using keyboard shortcut (#2999)
* docs: only render mobile search bar on mobile devices * docs: prevent rendering desktop search bar on mobile devices
This commit is contained in:
1 parent
cbd5943ddb
commit
76d6d26b3a
2 files changed
+12
-4
No files matched your search
@@ -9,6 +9,7 @@ import DocSidebarItem from '@theme/DocSidebarItem';
|
|||||||
import SearchBar from '../../SearchBar';
|
import SearchBar from '../../SearchBar';
|
||||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||||
import AnnouncementBar from '@theme/AnnouncementBar';
|
import AnnouncementBar from '@theme/AnnouncementBar';
|
||||||
|
import {useWindowSize} from '@docusaurus/theme-common';
|
||||||
|
|
||||||
function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
||||||
const {
|
const {
|
||||||
@@ -20,6 +21,7 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
|||||||
} = useThemeConfig();
|
} = useThemeConfig();
|
||||||
const isBrowser = useIsBrowser()
|
const isBrowser = useIsBrowser()
|
||||||
const sidebarRef = useRef(null)
|
const sidebarRef = useRef(null)
|
||||||
|
const windowSize = useWindowSize();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isBrowser && sidebarRef.current) {
|
if (isBrowser && sidebarRef.current) {
|
||||||
@@ -55,7 +57,7 @@ function DocSidebarDesktop({path, sidebar, onCollapse, isHidden}) {
|
|||||||
ref={sidebarRef}>
|
ref={sidebarRef}>
|
||||||
{hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
|
{hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
|
||||||
<div className={styles.sidebarSearchContainer}>
|
<div className={styles.sidebarSearchContainer}>
|
||||||
<SearchBar />
|
{windowSize !== 'mobile' && <SearchBar />}
|
||||||
</div>
|
</div>
|
||||||
<AnnouncementBar />
|
<AnnouncementBar />
|
||||||
<Content path={path} sidebar={sidebar} />
|
<Content path={path} sidebar={sidebar} />
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle';
|
|||||||
import NavbarLogo from '@theme/Navbar/Logo';
|
import NavbarLogo from '@theme/Navbar/Logo';
|
||||||
import NavbarSearch from '@theme/Navbar/Search';
|
import NavbarSearch from '@theme/Navbar/Search';
|
||||||
import styles from './styles.module.css';
|
import styles from './styles.module.css';
|
||||||
|
import {useWindowSize} from '@docusaurus/theme-common';
|
||||||
|
|
||||||
function useNavbarItems() {
|
function useNavbarItems() {
|
||||||
// TODO temporary casting until ThemeConfig type is improved
|
// TODO temporary casting until ThemeConfig type is improved
|
||||||
return useThemeConfig().navbar.items;
|
return useThemeConfig().navbar.items;
|
||||||
@@ -36,6 +38,8 @@ export default function NavbarContent() {
|
|||||||
const mobileSidebar = useNavbarMobileSidebar();
|
const mobileSidebar = useNavbarMobileSidebar();
|
||||||
const items = useNavbarItems();
|
const items = useNavbarItems();
|
||||||
const [leftItems, rightItems] = splitNavbarItems(items);
|
const [leftItems, rightItems] = splitNavbarItems(items);
|
||||||
|
const windowSize = useWindowSize();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavbarContentLayout
|
<NavbarContentLayout
|
||||||
left={
|
left={
|
||||||
@@ -52,9 +56,11 @@ export default function NavbarContent() {
|
|||||||
<>
|
<>
|
||||||
<NavbarItems items={rightItems} />
|
<NavbarItems items={rightItems} />
|
||||||
<NavbarColorModeToggle className={styles.colorModeToggle} />
|
<NavbarColorModeToggle className={styles.colorModeToggle} />
|
||||||
<NavbarSearch>
|
{windowSize === 'mobile' && (
|
||||||
<SearchBar />
|
<NavbarSearch>
|
||||||
</NavbarSearch>
|
<SearchBar />
|
||||||
|
</NavbarSearch>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in new issue
Block a user