diff --git a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts index a4ca7e346018..e95e10bada60 100644 --- a/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts +++ b/packages/docusaurus-theme-classic/src/__tests__/validateThemeConfig.test.ts @@ -242,6 +242,12 @@ describe('themeConfig', () => { position: 'left', label: 'Current version', }, + // Search with className + { + type: 'search', + position: 'right', + className: 'search-bar-wrapper', + }, ], }, }; diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index ef8c33023fd2..e2f671457e22 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -775,6 +775,7 @@ declare module '@theme/Navbar/Search' { export interface Props { readonly children: ReactNode; + readonly className?: string; } export default function NavbarSearch(props: Props): JSX.Element; diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx index 9ab92085eca5..038950d3d36d 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/Content/index.tsx @@ -56,7 +56,7 @@ export default function NavbarContent(): JSX.Element { const items = useNavbarItems(); const [leftItems, rightItems] = splitNavbarItems(items); - const autoAddSearchBar = !items.some((item) => item.type === 'search'); + const searchBarItem = items.find((item) => item.type === 'search'); return ( - {autoAddSearchBar && ( - + {searchBarItem && ( + )} diff --git a/packages/docusaurus-theme-classic/src/theme/Navbar/Search/index.tsx b/packages/docusaurus-theme-classic/src/theme/Navbar/Search/index.tsx index 8d3fe1b19d2f..236d237aa082 100644 --- a/packages/docusaurus-theme-classic/src/theme/Navbar/Search/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/Navbar/Search/index.tsx @@ -6,10 +6,14 @@ */ import React from 'react'; +import clsx from 'clsx'; import type {Props} from '@theme/Navbar/Search'; import styles from './styles.module.css'; -export default function NavbarSearch({children}: Props): JSX.Element { - return
{children}
; +export default function NavbarSearch({ + children, + className, +}: Props): JSX.Element { + return
{children}
; } diff --git a/packages/docusaurus-theme-classic/src/validateThemeConfig.ts b/packages/docusaurus-theme-classic/src/validateThemeConfig.ts index 9bdf1a8d9da8..0ca924712099 100644 --- a/packages/docusaurus-theme-classic/src/validateThemeConfig.ts +++ b/packages/docusaurus-theme-classic/src/validateThemeConfig.ts @@ -202,6 +202,7 @@ const LocaleDropdownNavbarItemSchema = NavbarItemBaseSchema.append({ const SearchItemSchema = Joi.object({ type: Joi.string().equal('search').required(), + className: Joi.string().default(''), }); const NavbarItemSchema = Joi.object({ diff --git a/website/docs/api/themes/theme-configuration.md b/website/docs/api/themes/theme-configuration.md index 02e3c66db8f5..41ee5ae27758 100644 --- a/website/docs/api/themes/theme-configuration.md +++ b/website/docs/api/themes/theme-configuration.md @@ -602,6 +602,7 @@ However, with this special navbar item type, you can change the default location | --- | --- | --- | --- | | `type` | `'search'` | **Required** | Sets the type of this item to a search bar. | | `position` | 'left' \| 'right' | `'left'` | The side of the navbar this item should appear on. | +| `className` | `string` | `''` | Custom CSS class for this navbar item. |