Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust spacing for custom search properly #7164

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,16 @@ declare module '@theme/Navbar/MobileSidebar/Header' {
export default function NavbarMobileSidebarHeader(): JSX.Element;
}

declare module '@theme/Navbar/Search' {
import type {ReactNode} from 'react';

export interface Props {
readonly children: ReactNode;
}

export default function NavbarSearch(props: Props): JSX.Element;
}

declare module '@theme/NavbarItem/DefaultNavbarItem' {
import type {Props as NavbarNavLinkProps} from '@theme/NavbarItem/NavbarNavLink';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from '@docusaurus/theme-common';
import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle';
import NavbarLogo from '@theme/Navbar/Logo';
import NavbarSearch from '@theme/Navbar/Search';
import styles from './styles.module.css';

function useNavbarItems() {
Expand Down Expand Up @@ -73,7 +74,11 @@ export default function NavbarContent(): JSX.Element {
<>
<NavbarItems items={rightItems} />
<NavbarColorModeToggle className={styles.colorModeToggle} />
{autoAddSearchBar && <SearchBar />}
{autoAddSearchBar && (
<NavbarSearch>
<SearchBar />
</NavbarSearch>
)}
</>
}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import React from 'react';
import type {Props} from '@theme/Navbar/Search';

import styles from './styles.module.css';

export default function NavbarSearch({children}: Props): JSX.Element {
return <div className={styles.searchBox}>{children}</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@
import React from 'react';
import type {Props} from '@theme/NavbarItem/SearchNavbarItem';
import SearchBar from '@theme/SearchBar';
import NavbarSearch from '@theme/Navbar/Search';

export default function SearchNavbarItem({mobile}: Props): JSX.Element | null {
if (mobile) {
return null;
}

return <SearchBar />;
return (
<NavbarSearch>
<SearchBar />
</NavbarSearch>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {DocSearchButton, useDocSearchKeyboardEvents} from '@docsearch/react';
import type {SearchClient} from 'algoliasearch/lite';
import {useAlgoliaContextualFacetFilters} from '@docusaurus/theme-search-algolia/client';
import Translate, {translate} from '@docusaurus/Translate';
import styles from './styles.module.css';

import type {
DocSearchModal as DocSearchModalType,
Expand Down Expand Up @@ -233,19 +232,17 @@ function DocSearch({
/>
</Head>

<div className={styles.searchBox}>
<DocSearchButton
onTouchStart={importDocSearchModalIfNeeded}
onFocus={importDocSearchModalIfNeeded}
onMouseOver={importDocSearchModalIfNeeded}
onClick={onOpen}
ref={searchButtonRef}
translations={{
buttonText: translatedSearchLabel,
buttonAriaLabel: translatedSearchLabel,
}}
/>
</div>
<DocSearchButton
onTouchStart={importDocSearchModalIfNeeded}
onFocus={importDocSearchModalIfNeeded}
onMouseOver={importDocSearchModalIfNeeded}
onClick={onOpen}
ref={searchButtonRef}
translations={{
buttonText: translatedSearchLabel,
buttonAriaLabel: translatedSearchLabel,
}}
/>

{isOpen &&
DocSearchModal &&
Expand Down