:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(max): dismiss slash command popover on Esc (#60982)
ruby childs2d6c14f1ce9c
diff --git a/frontend/src/scenes/max/components/QuestionInput.test.tsx b/frontend/src/scenes/max/components/QuestionInput.test.tsxnew file mode 100644index 000000000000..543ea262444b--- /dev/null+++ b/frontend/src/scenes/max/components/QuestionInput.test.tsx@@ -0,0 +1,79 @@+import '@testing-library/jest-dom'++import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'+import { BindLogic, Provider } from 'kea'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { maxGlobalLogic } from '../maxGlobalLogic'+import { maxLogic } from '../maxLogic'+import { maxThreadLogic } from '../maxThreadLogic'+import { maxMocks } from '../testUtils'+import { QuestionInput } from './QuestionInput'++jest.mock(+ '@posthog/hogvm',+ () => ({+ exec: jest.fn(),+ execAsync: jest.fn(),+ }),+ { virtual: true }+)++describe('QuestionInput slash command autocomplete', () => {+ let maxLogicInstance: ReturnType<typeof maxLogic.build>+ let threadLogicInstance: ReturnType<typeof maxThreadLogic.build>++ beforeEach(() => {+ useMocks(maxMocks)+ initKeaTests()++ const maxGlobalLogicInstance = maxGlobalLogic()+ maxGlobalLogicInstance.mount()+ jest.spyOn(maxGlobalLogicInstance.selectors, 'dataProcessingAccepted').mockReturnValue(true)++ maxLogicInstance = maxLogic({ tabId: 'test' })+ maxLogicInstance.mount()++ const threadProps = { tabId: 'test', conversationId: maxLogicInstance.values.frontendConversationId }+ threadLogicInstance = maxThreadLogic(threadProps)+ threadLogicInstance.mount()++ render(+ <Provider>+ <BindLogic logic={maxLogic} props={{ tabId: 'test' }}>+ <BindLogic logic={maxThreadLogic} props={threadProps}>+ <QuestionInput />+ </BindLogic>+ </BindLogic>+ </Provider>+ )+ })++ afterEach(() => {+ cleanup()+ threadLogicInstance?.unmount()+ maxLogicInstance?.cache.eventSourceController?.abort()+ maxLogicInstance?.unmount()+ jest.restoreAllMocks()+ })++ const slashCommandItem = (): HTMLElement | null => screen.queryByText('/init')++ it('reopens the popover after Escape dismisses it and a fresh slash is typed', async () => {+ const input = screen.getByRole('textbox') as HTMLTextAreaElement++ fireEvent.change(input, { target: { value: '/' } })+ await waitFor(() => expect(slashCommandItem()).toBeInTheDocument())++ fireEvent.keyDown(document, { key: 'Escape' })+ await waitFor(() => expect(slashCommandItem()).not.toBeInTheDocument())++ fireEvent.change(input, { target: { value: '' } })+ await waitFor(() => expect(input.value).toBe(''))++ fireEvent.change(input, { target: { value: '/' } })+ await waitFor(() => expect(slashCommandItem()).toBeInTheDocument())+ })+})diff --git a/frontend/src/scenes/max/components/QuestionInput.tsx b/frontend/src/scenes/max/components/QuestionInput.tsxindex 35fde019b81f..bb1abdd0020f 100644--- a/frontend/src/scenes/max/components/QuestionInput.tsx+++ b/frontend/src/scenes/max/components/QuestionInput.tsx@@ -176,6 +176,9 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputPropsconst isImpersonatedInternalConversation = user?.is_impersonated && conversation?.is_internalconst [showAutocomplete, setShowAutocomplete] = useState(false)+ // Tracks an explicit dismissal (e.g. Esc) so the popover stays closed while the+ // user keeps typing a message that still starts with "/". "/" + Esc is a valid path.+ const [autocompleteDismissed, setAutocompleteDismissed] = useState(false)const [editingQueueId, setEditingQueueId] = useState<string | null>(null)const displayQueuedMessages = useMemo(() => [...queuedMessages].reverse(), [queuedMessages])const hasQuestion = question.trim().length > 0@@ -185,11 +188,17 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps// Update autocomplete visibility when question changesuseEffect(() => {const isSlashCommand = question[0] === '/'- if (isSlashCommand && !showAutocomplete) {+ // Once the input is no longer a slash command, clear any prior dismissal so+ // typing "/" again later reopens the popover.+ if (!isSlashCommand && autocompleteDismissed) {+ setAutocompleteDismissed(false)+ }+ const shouldShow = isSlashCommand && !autocompleteDismissed+ if (shouldShow && !showAutocomplete) {posthog.capture('Max slash command autocomplete shown')}- setShowAutocomplete(isSlashCommand)- }, [question, showAutocomplete])+ setShowAutocomplete(shouldShow)+ }, [question, showAutocomplete, autocompleteDismissed])let disabledReason = submissionDisabledReasonif (threadLoading && !isQueueingSubmission) {@@ -277,7 +286,10 @@ export const QuestionInput = React.forwardRef<HTMLDivElement, QuestionInputProps) : (<SlashCommandAutocompletevisible={showAutocomplete}- onClose={() => setShowAutocomplete(false)}+ onClose={() => {+ setShowAutocomplete(false)+ setAutocompleteDismissed(true)+ }}><div className="relative w-full">{!question && (