Skip to content

: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.

fix(taxonomy): close category menu before docking (#99912)

Paul D'Ambra7f6a3fa76527
diff --git a/frontend/src/lib/components/TaxonomicFilter/CategoryDropdown.tsx b/frontend/src/lib/components/TaxonomicFilter/CategoryDropdown.tsx
index f2febee02a49..42eab02086c8 100644
--- a/frontend/src/lib/components/TaxonomicFilter/CategoryDropdown.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/CategoryDropdown.tsx
@@ -1,6 +1,8 @@
import clsx from 'clsx'
import { useActions, useValues } from 'kea'
import posthog from 'posthog-js'
+import { useState } from 'react'
+import { flushSync } from 'react-dom'
import { IconChevronDown, IconSidebarClose, IconSidebarOpen } from '@posthog/icons'
@@ -22,6 +24,7 @@ export function CategoryDropdown({
onAfterChange?: () => void
joinedToInput?: boolean
}): JSX.Element | null {
+ const [menuVisible, setMenuVisible] = useState(false)
const { activeTab, taxonomicGroups, taxonomicGroupTypes } = useValues(taxonomicFilterLogic)
const { markUserInteraction, setActiveTab } = useActions(taxonomicFilterLogic)
const { categoryRailPinned } = useValues(taxonomicFilterCategoryLayoutLogic)
@@ -29,6 +32,7 @@ export function CategoryDropdown({
const { reportTaxonomicFilterCategorySelected } = useActions(eventUsageLogic)
const onVisibilityChange = (visible: boolean): void => {
+ setMenuVisible(visible)
if (visible) {
markUserInteraction()
posthog.capture('taxonomic filter category dropdown opened', {
@@ -70,6 +74,7 @@ export function CategoryDropdown({
icon: categoryRailPinned ? <IconSidebarClose /> : <IconSidebarOpen />,
'data-attr': 'taxonomic-category-rail-toggle',
onClick: () => {
+ flushSync(() => setMenuVisible(false))
markUserInteraction()
setCategoryRailPinned(!categoryRailPinned)
onAfterChange?.()
@@ -84,6 +89,7 @@ export function CategoryDropdown({
return (
<LemonMenu
items={items}
+ visible={menuVisible}
onVisibilityChange={onVisibilityChange}
activeItemIndex={activeItemIndex >= 0 ? activeItemIndex : undefined}
placement="bottom-start"
diff --git a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
index 1a20ed7cea5a..c28ae34d6b73 100644
--- a/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/TaxonomicFilter.test.tsx
@@ -1517,6 +1517,9 @@ describe('TaxonomicFilter', () => {
await userEvent.click(await screen.findByTestId('taxonomic-category-rail-toggle'))
expect(await screen.findByText('Categories')).toBeInTheDocument()
+ await waitFor(() => {
+ expect(screen.queryByTestId('taxonomic-category-rail-toggle')).not.toBeInTheDocument()
+ })
expect(screen.getByTestId('taxonomic-category-dropdown-trigger-pill')).toHaveClass('hidden')
await userEvent.click(screen.getByTestId('taxonomic-category-rail-unpin'))