Open search in the current space from scoped search buttons

This commit is contained in:
Peter White
2026-10-07 08:56:39 +02:00
parent 2137c2df7b
commit 6165674dc7
3 changed files with 14 additions and 3 deletions
@@ -0,0 +1,5 @@
---
"gitbook": patch
---
Let search buttons open search limited to the current space.
@@ -13,9 +13,14 @@ const INPUT_SIZE_MAP: Record<NonNullable<ButtonProps['size']>, 'small' | 'medium
};
export function InlineActionButton(
props: { action: 'ask' | 'search'; query?: string } & { buttonProps: ButtonProps } // TODO: Type this properly: Pick<api.DocumentInlineButton, 'action' | 'query'> & { 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<api.DocumentInlineButton, 'action' | 'query'> & { 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,
}));
@@ -47,6 +47,7 @@ export function InlineButton(props: InlineProps<api.DocumentInlineButton>) {
<InlineActionButton
action={inline.data.action.action}
query={inline.data.action.query ?? ''}
scope={inline.data.action.scope}
buttonProps={buttonProps}
/>
);