From 9f447aab294dbb2f1a68d9e9cfd78cfe07b2a34c Mon Sep 17 00:00:00 2001 From: Peter White <1788320+peterwhite@users.noreply.github.com> Date: Wed, 7 Oct 2026 17:04:19 +0200 Subject: [PATCH] Open search in the current space from scoped search buttons (#4666) --- .changeset/search-button-current-space.md | 5 +++++ bun.lock | 4 ++-- package.json | 2 +- .../components/DocumentView/InlineActionButton.tsx | 11 ++++++++--- .../src/components/DocumentView/InlineButton.tsx | 5 +++++ 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 .changeset/search-button-current-space.md diff --git a/.changeset/search-button-current-space.md b/.changeset/search-button-current-space.md new file mode 100644 index 000000000..d627612c7 --- /dev/null +++ b/.changeset/search-button-current-space.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Let search buttons open search limited to the current space. diff --git a/bun.lock b/bun.lock index 9ae859236..b8158ccac 100644 --- a/bun.lock +++ b/bun.lock @@ -355,7 +355,7 @@ }, "catalog": { "@base-ui/react": "^1.7.0", - "@gitbook/api": "0.204.0", + "@gitbook/api": "0.205.0", "@scalar/api-client-react": "^1.3.46", "@tsconfig/node20": "^20.1.6", "@tsconfig/strictest": "^2.0.6", @@ -727,7 +727,7 @@ "@fortawesome/fontawesome-svg-core": ["@fortawesome/fontawesome-svg-core@7.2.0", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "7.2.0" } }, "sha512-6639htZMjEkwskf3J+e6/iar+4cTNM9qhoWuRfj9F3eJD6r7iCzV1SWnQr2Mdv0QT0suuqU8BoJCZUyCtP9R4Q=="], - "@gitbook/api": ["@gitbook/api@0.204.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-SJCe0Ipyt+V5HZX4EZpFO8AHTOWIMwj2ljQTbcqgU7rVOAyCNDzILp8mRk9stbboSi1pv09+rDnZK1ZguPvFTw=="], + "@gitbook/api": ["@gitbook/api@0.205.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-jjkPAhPw6tja1N0ZPKqVsaV+opN8IS7yP1oZHHbcacZ477angPCo9YqiJJYWAl0tQ5OcKTuQbrsqhZSuwKM2Kw=="], "@gitbook/browser-types": ["@gitbook/browser-types@workspace:packages/browser-types"], diff --git a/package.json b/package.json index b004d2a7d..8b6c98171 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "@tsconfig/strictest": "^2.0.6", "@tsconfig/node20": "^20.1.6", "@base-ui/react": "^1.7.0", - "@gitbook/api": "0.204.0", + "@gitbook/api": "0.205.0", "@scalar/api-client-react": "^1.3.46", "@types/react": "^19.0.0", "@types/react-dom": "^19.0.0", diff --git a/packages/gitbook/src/components/DocumentView/InlineActionButton.tsx b/packages/gitbook/src/components/DocumentView/InlineActionButton.tsx index d794bef67..bf0a6ac04 100644 --- a/packages/gitbook/src/components/DocumentView/InlineActionButton.tsx +++ b/packages/gitbook/src/components/DocumentView/InlineActionButton.tsx @@ -13,9 +13,14 @@ const INPUT_SIZE_MAP: Record, 'small' | 'medium }; export function InlineActionButton( - props: { action: 'ask' | 'search'; query?: string } & { buttonProps: ButtonProps } // TODO: Type this properly: Pick & { buttonProps: ButtonProps } + props: { + action: 'ask' | 'search'; + query?: string; + /** Where a search runs: the whole site, or only the space the visitor is reading. */ + scope?: 'site' | 'space'; + } & { buttonProps: ButtonProps } // TODO: Type this properly: Pick & { buttonProps: ButtonProps } ) { - const { action, query, buttonProps } = props; + const { action, query, scope, buttonProps } = props; const { assistants } = useAI(); const chatState = useAIChatState(); @@ -29,7 +34,7 @@ export function InlineActionButton( setSearchState((prev) => ({ ...prev, ask: null, - scope: 'default', + scope: scope === 'space' ? 'current' : 'default', query: value ?? query, open: true, })); diff --git a/packages/gitbook/src/components/DocumentView/InlineButton.tsx b/packages/gitbook/src/components/DocumentView/InlineButton.tsx index 40ba19c41..7c1297b82 100644 --- a/packages/gitbook/src/components/DocumentView/InlineButton.tsx +++ b/packages/gitbook/src/components/DocumentView/InlineButton.tsx @@ -47,6 +47,11 @@ export function InlineButton(props: InlineProps) { );