Skip to content

Commit 46806ad

Browse files
authored
fix(query-bar): prevent default for mousedown event to prevent editor focus on placeholder click (#4721)
1 parent 31a8854 commit 46806ad

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/compass-query-bar/src/components/generative-ai/ai-experience-entry.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,20 @@ function createAIPlaceholderHTMLPlaceholder({
9191
containerEl.appendChild(placeholderTextEl);
9292

9393
const aiButtonEl = document.createElement('button');
94-
aiButtonEl.onclick = (e) => {
94+
// By default placeholder container will have pointer events disabled
95+
aiButtonEl.style.pointerEvents = 'auto';
96+
// We stop mousedown from propagating and preventing default behavior to avoid
97+
// input getting focused on placeholder click (that's the event that
98+
// codemirror uses internally to set focus to the input)
99+
aiButtonEl.addEventListener('mousedown', (e) => {
100+
e.preventDefault();
101+
e.stopPropagation();
102+
});
103+
aiButtonEl.addEventListener('click', (e) => {
95104
e.preventDefault();
96105
e.stopPropagation();
97106
onClickAI();
98-
};
107+
});
99108

100109
aiButtonEl.className = cx(
101110
aiQueryEntryStyles,

packages/compass-query-bar/src/components/query-bar.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ const moreOptionsContainerStyles = css({
7575
const filterContainerStyles = css({
7676
position: 'relative',
7777
flexGrow: 1,
78-
79-
// Override codemirror styles to make the `Ask AI` button clickable.
80-
'& .cm-placeholder': {
81-
pointerEvents: 'auto !important' as any, // Cast to any as !important errors ts.
82-
},
8378
});
8479

8580
const filterLabelStyles = css({

0 commit comments

Comments
 (0)