Skip to content

Commit f08dd29

Browse files
authored
Fix Search results are not clickable (#3595)
1 parent ca2dfa3 commit f08dd29

File tree

7 files changed

+36
-31
lines changed

7 files changed

+36
-31
lines changed

.changeset/slimy-pumpkins-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gitbook": patch
3+
---
4+
5+
Fix Search results are not clickable on sites without header

packages/gitbook/src/components/Header/Header.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { GitBookSiteContext } from '@/lib/context';
33
import { CONTAINER_STYLE, HEADER_HEIGHT_DESKTOP } from '@/components/layout';
44
import { getSpaceLanguage, t } from '@/intl/server';
55
import { tcls } from '@/lib/tailwind';
6+
import { SearchContainer } from '../Search';
67
import { SiteSectionTabs, encodeClientSiteSections } from '../SiteSections';
78
import { HeaderLink } from './HeaderLink';
89
import { HeaderLinkMore } from './HeaderLinkMore';
@@ -17,9 +18,8 @@ import { SpacesDropdown } from './SpacesDropdown';
1718
export function Header(props: {
1819
context: GitBookSiteContext;
1920
withTopHeader?: boolean;
20-
search?: React.ReactNode;
2121
}) {
22-
const { context, withTopHeader, search } = props;
22+
const { context, withTopHeader } = props;
2323
const { siteSpace, siteSpaces, sections, customization } = context;
2424

2525
return (
@@ -117,7 +117,13 @@ export function Header(props: {
117117
: ['order-last']
118118
)}
119119
>
120-
{search}
120+
<SearchContainer
121+
style={customization.styling.search}
122+
isMultiVariants={siteSpaces.length > 1}
123+
spaceTitle={siteSpace.title}
124+
siteSpaceId={siteSpace.id}
125+
viewport={!withTopHeader ? 'mobile' : undefined}
126+
/>
121127
</div>
122128

123129
{customization.header.links.length > 0 && (

packages/gitbook/src/components/Search/SearchContainer.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ interface SearchContainerProps {
2323
isMultiVariants: boolean;
2424
style: CustomizationSearchStyle;
2525
className?: string;
26+
viewport?: 'desktop' | 'mobile';
2627
}
2728

2829
/**
2930
* Client component to render the search input and results.
3031
*/
3132
export function SearchContainer(props: SearchContainerProps) {
32-
const { siteSpaceId, spaceTitle, isMultiVariants, style, className } = props;
33+
const { siteSpaceId, spaceTitle, isMultiVariants, style, className, viewport } = props;
3334

3435
const { assistants } = useAI();
3536

@@ -158,6 +159,8 @@ export function SearchContainer(props: SearchContainerProps) {
158159

159160
const showAsk = withSearchAI && normalizedAsk; // withSearchAI && normalizedAsk;
160161

162+
const visible = viewport === 'desktop' ? !isMobile : viewport === 'mobile' ? isMobile : true;
163+
161164
return (
162165
<SearchAskProvider value={searchAsk}>
163166
<Popover
@@ -181,7 +184,7 @@ export function SearchContainer(props: SearchContainerProps) {
181184
) : null
182185
}
183186
rootProps={{
184-
open: state?.open ?? false,
187+
open: visible && (state?.open ?? false),
185188
onOpenChange: (open) => {
186189
open ? onOpen() : onClose();
187190
},

packages/gitbook/src/components/Search/SearchInput.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
4646
}, [isOpen, value]);
4747

4848
return (
49-
<div className="relative flex size-9 grow">
49+
<div className={tcls('relative flex size-9 grow', className)}>
5050
{/* biome-ignore lint/a11y/useKeyWithClickEvents: this div needs an onClick to show the input on mobile, where it's normally hidden.
5151
Normally you'd also need to add a keyboard trigger to do the same without a pointer, but in this case the input already be focused on its own. */}
5252
<div
@@ -62,8 +62,7 @@ export const SearchInput = React.forwardRef<HTMLDivElement, SearchInputProps>(
6262
'theme-bold:border-header-link/3 has-[input:focus-visible]:theme-bold:border-header-link/5 has-[input:focus-visible]:theme-bold:bg-header-link/3 has-[input:focus-visible]:theme-bold:ring-header-link/5',
6363
'theme-bold:before:absolute theme-bold:before:inset-0 theme-bold:before:bg-header-background/7 theme-bold:before:backdrop-blur-xl ', // Special overlay to make the transparent colors of theme-bold visible.
6464
'relative z-30 shrink grow justify-start max-md:absolute max-md:right-0',
65-
isOpen ? 'max-md:w-56' : 'max-md:w-[38px]',
66-
className
65+
isOpen ? 'max-md:w-56' : 'max-md:w-[38px]'
6766
)}
6867
>
6968
{value && isOpen ? (

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
CustomizationHeaderPreset,
55
CustomizationSearchStyle,
66
} from '@gitbook/api';
7-
import React from 'react';
7+
import type React from 'react';
88

99
import { Footer } from '@/components/Footer';
1010
import { Header, HeaderLogo } from '@/components/Header';
@@ -52,23 +52,6 @@ export function SpaceLayout(props: {
5252
customization.footer.logo ||
5353
customization.footer.groups?.length;
5454

55-
const search = (
56-
<div className="flex grow items-center gap-2">
57-
<React.Suspense fallback={null}>
58-
<SearchContainer
59-
style={
60-
customization.header.preset === CustomizationHeaderPreset.None
61-
? CustomizationSearchStyle.Subtle
62-
: customization.styling.search
63-
}
64-
isMultiVariants={siteSpaces.length > 1}
65-
spaceTitle={siteSpace.title}
66-
siteSpaceId={siteSpace.id}
67-
/>
68-
</React.Suspense>
69-
</div>
70-
);
71-
7255
const eventUrl = new URL(
7356
context.linker.toAbsoluteURL(context.linker.toPathInSite('/~gitbook/__evt'))
7457
);
@@ -94,7 +77,7 @@ export function SpaceLayout(props: {
9477
visitorCookieTrackingEnabled={customization.insights?.trackingCookie}
9578
>
9679
<Announcement context={context} />
97-
<Header withTopHeader={withTopHeader} context={context} search={search} />
80+
<Header withTopHeader={withTopHeader} context={context} />
9881
{customization.ai?.mode === CustomizationAIMode.Assistant ? (
9982
<AIChat trademark={customization.trademark.enabled} />
10083
) : null}
@@ -121,7 +104,7 @@ export function SpaceLayout(props: {
121104
className={tcls(
122105
'hidden',
123106
'pr-4',
124-
'md:flex',
107+
'lg:flex',
125108
'grow-0',
126109
'flex-wrap',
127110
'dark:shadow-light/1',
@@ -135,7 +118,16 @@ export function SpaceLayout(props: {
135118
innerHeader={
136119
// displays the search button and/or the space dropdown in the ToC according to the header/variant settings. E.g if there is no header, the search button will be displayed in the ToC.
137120
<>
138-
{!withTopHeader && search}
121+
{!withTopHeader && (
122+
<SearchContainer
123+
style={CustomizationSearchStyle.Subtle}
124+
isMultiVariants={siteSpaces.length > 1}
125+
spaceTitle={siteSpace.title}
126+
siteSpaceId={siteSpace.id}
127+
className="max-lg:hidden"
128+
viewport="desktop"
129+
/>
130+
)}
139131
{!withTopHeader && withSections && sections && (
140132
<SiteSectionList
141133
className={tcls('hidden', 'lg:block')}

packages/gitbook/src/components/TableOfContents/TableOfContents.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export async function TableOfContents(props: {
9696
'page-has-toc:[html.sidebar-filled.circular-corners_&]:rounded-3xl'
9797
)}
9898
>
99-
{innerHeader && <div className="px-5 *:my-4">{innerHeader}</div>}
99+
{innerHeader && <div className="flex px-5 *:my-4">{innerHeader}</div>}
100100
<TOCScrollContainer // The scrollview inside the sidebar
101101
className={tcls(
102102
'flex grow flex-col p-2',

packages/gitbook/src/components/hooks/useIsMobile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as React from 'react';
44

5-
export function useIsMobile(breakpoint = 640): boolean {
5+
export function useIsMobile(breakpoint = 1024): boolean {
66
const [isMobile, setIsMobile] = React.useState(false);
77

88
React.useEffect(() => {

0 commit comments

Comments
 (0)