Skip to content

Commit e20d37d

Browse files
authored
Merge pull request #4448 from Blargian/fix_search_bug
Bug fix: typing `/` while Ask AI widget is open triggers Docsearch pop-up (again)
2 parents a64ca19 + 364f0a2 commit e20d37d

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/theme/SearchBar/utils/aiConflictHandler.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import { SEARCH_SHORTCUTS, INPUT_FIELD_SELECTORS } from '../searchConstants';
77
*/
88
function isInputField(activeElement) {
99
if (!activeElement) return false;
10-
10+
11+
// Check for Kapa AI input by placeholder text (most reliable)
12+
if (activeElement.placeholder === "Ask me a question about ClickHouse...") {
13+
return true;
14+
}
15+
1116
return INPUT_FIELD_SELECTORS.some(selector => {
1217
if (selector.startsWith('#') || selector.startsWith('[')) {
1318
return activeElement.matches?.(selector) || activeElement.closest?.(selector);
@@ -48,13 +53,18 @@ function isSearchShortcut(event) {
4853
export function handleSearchKeyboardConflict(event, isAskAIOpen) {
4954
if (!isSearchShortcut(event)) return;
5055

51-
if (shouldPreventSearchAction(isAskAIOpen)) {
52-
// Special case: allow "/" in input fields
53-
if (event.key === SEARCH_SHORTCUTS.SLASH && !shouldPreventSearchAction(isAskAIOpen)) {
54-
event.stopImmediatePropagation();
55-
} else {
56-
event.preventDefault();
57-
event.stopImmediatePropagation();
58-
}
56+
// If Ask AI is not open, don't interfere with normal search behavior
57+
if (!isAskAIOpen) return;
58+
59+
const activeElement = document.activeElement;
60+
61+
// If we're typing in an input field when AI is open, allow "/" but prevent search modal
62+
if (event.key === SEARCH_SHORTCUTS.SLASH && isInputField(activeElement)) {
63+
event.stopImmediatePropagation();
64+
return;
5965
}
66+
67+
// Otherwise, when AI is open and not in input field, prevent all search shortcuts
68+
event.preventDefault();
69+
event.stopImmediatePropagation();
6070
}

0 commit comments

Comments
 (0)