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(today): keep the rail nav on narrow windows (#109586)

Shy Alterd31b61eb1f2e
diff --git a/frontend/src/layout/navigation-3000/Navigation.tsx b/frontend/src/layout/navigation-3000/Navigation.tsx
index 887d03d83963..c75b5ed34543 100644
--- a/frontend/src/layout/navigation-3000/Navigation.tsx
+++ b/frontend/src/layout/navigation-3000/Navigation.tsx
@@ -50,7 +50,12 @@ export function Navigation({
const { scenePanelIsPresent, scenePanelOpenManual, sceneTakeoverActive } = useValues(sceneLayoutLogic)
const { sidePanelOpen } = useValues(sidePanelStateLogic)
const { sidePanelWidth } = useValues(panelLayoutLogic)
- const { leftNavWidth: todayLeftNavWidth, todayRailEnabled: todayRail } = useValues(todayShellLogic)
+ const {
+ leftNavWidth: todayLeftNavWidth,
+ todayRailEnabled: todayRail,
+ sidebarVisible: todaySidebarVisible,
+ } = useValues(todayShellLogic)
+ const todayDrawerOpen = todayRail && mobileLayout && todaySidebarVisible
// SceneMenuBar (when enabled) replaces ProjectNotice's role of conveying project-level
// context above scene content, so we hide the notice for users on the new menu bar.
@@ -146,7 +151,7 @@ export function Navigation({
</a>
<div
className={cn('app-layout bg-surface-tertiary', {
- 'app-layout--mobile': mobileLayout,
+ 'app-layout--mobile': mobileLayout && !todayRail,
TodayAppLayout: todayRail,
})}
style={
@@ -182,9 +187,11 @@ export function Navigation({
className={cn(
'@container/main-content-container main-content-container flex overflow-hidden lg:rounded border-t lg:border border-primary relative lg:mr-1 lg:mb-1 lg:mt-1',
{
+ 'rounded border mr-1 mb-1 mt-1': todayRail,
'rounded-r-none': sidePanelOpen,
}
)}
+ {...(todayDrawerOpen ? { inert: '' } : {})}
>
<main
ref={mainRef}
diff --git a/frontend/src/layout/today/TodayRail.tsx b/frontend/src/layout/today/TodayRail.tsx
index 6d28e6a5d3a1..83ee381b584b 100644
--- a/frontend/src/layout/today/TodayRail.tsx
+++ b/frontend/src/layout/today/TodayRail.tsx
@@ -26,7 +26,7 @@ const RAIL_ITEMS: { pane: TodayRailPane; label: string; icon: JSX.Element }[] =
]
export function TodayRail(): JSX.Element {
- const { activePane, sidebarOpen } = useValues(todayShellLogic)
+ const { activePane, sidebarVisible } = useValues(todayShellLogic)
const { pickPane, toggleSidebar } = useActions(todayShellLogic)
const { toggleCommand } = useActions(commandLogic)
@@ -76,14 +76,14 @@ export function TodayRail(): JSX.Element {
<ButtonPrimitive
iconOnly
size="lg"
- aria-label={sidebarOpen ? 'Hide sidebar' : 'Show sidebar'}
- tooltip={sidebarOpen ? 'Hide sidebar' : 'Show sidebar'}
+ aria-label={sidebarVisible ? 'Hide sidebar' : 'Show sidebar'}
+ tooltip={sidebarVisible ? 'Hide sidebar' : 'Show sidebar'}
tooltipPlacement="right"
data-attr="today-rail-toggle-sidebar"
className="text-secondary [&_svg]:size-5"
onClick={toggleSidebar}
>
- {sidebarOpen ? <IconSidebarClose /> : <IconSidebarOpen />}
+ {sidebarVisible ? <IconSidebarClose /> : <IconSidebarOpen />}
</ButtonPrimitive>
<NewAccountMenu isLayoutNavCollapsed />
</div>
diff --git a/frontend/src/layout/today/TodayShell.scss b/frontend/src/layout/today/TodayShell.scss
index 737d61027d12..dbf1c839d4cf 100644
--- a/frontend/src/layout/today/TodayShell.scss
+++ b/frontend/src/layout/today/TodayShell.scss
@@ -17,6 +17,59 @@
height: 100%;
}
+.TodayShell__scrim {
+ position: fixed;
+ inset: 0 0 0 var(--today-rail-width);
+ z-index: var(--z-layout-navbar-under);
+ visibility: hidden;
+ background: rgb(21 21 21 / 18%);
+ opacity: 0;
+ transition:
+ opacity 240ms var(--today-ease),
+ visibility 240ms;
+
+ [theme='dark'] & {
+ background: rgb(0 0 0 / 55%);
+ }
+
+ &[data-open='true'] {
+ visibility: visible;
+ opacity: 1;
+ }
+}
+
+.TodayShell__drawer {
+ position: fixed;
+ top: 0;
+ bottom: 0;
+ left: var(--today-rail-width);
+ z-index: var(--z-layout-navbar);
+ max-width: calc(100vw - var(--today-rail-width) - 3rem);
+ visibility: hidden;
+ background: var(--today-paper);
+ border-right: 1px solid var(--today-line);
+ box-shadow: 24px 0 48px -24px rgb(0 0 0 / 28%);
+ opacity: 0;
+ transition:
+ transform 280ms var(--today-ease),
+ opacity 200ms var(--today-ease),
+ visibility 280ms;
+ transform: translateX(-12px);
+
+ &[data-open='true'] {
+ visibility: visible;
+ opacity: 1;
+ transform: none;
+ }
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .TodayShell__scrim,
+ .TodayShell__drawer {
+ transition: none;
+ }
+}
+
.TodayShell__pane {
flex: 1 1 auto;
min-height: 0;
diff --git a/frontend/src/layout/today/TodayShell.tsx b/frontend/src/layout/today/TodayShell.tsx
index 29f84951aff5..2b7d2bcede17 100644
--- a/frontend/src/layout/today/TodayShell.tsx
+++ b/frontend/src/layout/today/TodayShell.tsx
@@ -15,7 +15,7 @@ import { NewSpaceDialog } from 'products/tasks/frontend/spaces/NewSpaceDialog'
import { TodayLibrarySidebar } from './TodayLibrarySidebar'
import { TodayRail } from './TodayRail'
-import { TODAY_SIDEBAR_CLOSE_THRESHOLD, clampSidebarWidth, todayShellLogic } from './todayShellLogic'
+import { TODAY_RAIL_WIDTH, TODAY_SIDEBAR_CLOSE_THRESHOLD, clampSidebarWidth, todayShellLogic } from './todayShellLogic'
import { TodaySidebarFooter } from './TodaySidebarFooter'
import { TodaySpacesSidebar } from './TodaySpacesSidebar'
import { TodayToolsSidebar } from './TodayToolsSidebar'
@@ -24,9 +24,11 @@ const PANE_LABELS = { home: 'Today', spaces: 'Spaces', library: 'Library', tools
/** The left navigation under the Today layout: the rail, then the sidebar for the pane the rail has open. */
export function TodayShell({ className }: { className?: string }): JSX.Element {
- const { activePane, sidebarOpen, sidebarWidth } = useValues(todayShellLogic)
- const { setSidebarOpen, setSidebarWidth, toggleSidebar } = useActions(todayShellLogic)
+ const { activePane, mobileLayout, sidebarVisible, sidebarWidth } = useValues(todayShellLogic)
+ const { setMobileSidebarOpen, setSidebarOpen, setSidebarWidth, toggleSidebar } = useActions(todayShellLogic)
const sidebarRef = useRef<HTMLDivElement | null>(null)
+ const drawerRef = useRef<HTMLElement | null>(null)
+ const returnFocusRef = useRef<HTMLElement | null>(null)
const resizerLogicProps: ResizerLogicProps = {
// pinned: storage key for the persisted width. Renaming it resets everyone's sidebar width.
@@ -45,32 +47,80 @@ export function TodayShell({ className }: { className?: string }): JSX.Element {
setSidebarWidth(clampSidebarWidth(desiredSize))
}, [desiredSize, setSidebarWidth])
+ useEffect(() => {
+ if (!mobileLayout) {
+ return
+ }
+ if (sidebarVisible) {
+ returnFocusRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null
+ drawerRef.current?.focus()
+ } else if (returnFocusRef.current) {
+ if (returnFocusRef.current.isConnected) {
+ returnFocusRef.current.focus()
+ }
+ returnFocusRef.current = null
+ }
+ }, [mobileLayout, sidebarVisible])
+
+ const pane = (
+ <div className="TodayShell__pane">
+ {activePane === 'home' ? (
+ <TodayHomeSidebar />
+ ) : activePane === 'spaces' ? (
+ <TodaySpacesSidebar />
+ ) : activePane === 'library' ? (
+ <TodayLibrarySidebar />
+ ) : (
+ <TodayToolsSidebar />
+ )}
+ </div>
+ )
+
return (
<ToastProvider>
- <div className={cn('Today TodayShell', className)}>
+ <div
+ className={cn('Today TodayShell', className)}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ '--today-rail-width': `${TODAY_RAIL_WIDTH}px` } as React.CSSProperties}
+ >
<TodayRail />
- {sidebarOpen && (
- <aside
- ref={sidebarRef}
- className="TodayShell__sidebar relative"
- aria-label={PANE_LABELS[activePane]}
- // eslint-disable-next-line react/forbid-dom-props
- style={{ width: sidebarWidth }}
- >
- <div className="TodayShell__pane">
- {activePane === 'home' ? (
- <TodayHomeSidebar />
- ) : activePane === 'spaces' ? (
- <TodaySpacesSidebar />
- ) : activePane === 'library' ? (
- <TodayLibrarySidebar />
- ) : (
- <TodayToolsSidebar />
- )}
- </div>
- <TodaySidebarFooter />
- <Resizer {...resizerLogicProps} className="z-2" offset={0} />
- </aside>
+ {mobileLayout ? (
+ <>
+ <div
+ className="TodayShell__scrim"
+ data-open={sidebarVisible}
+ aria-hidden
+ onClick={() => setMobileSidebarOpen(false)}
+ />
+ <aside
+ ref={drawerRef}
+ tabIndex={-1}
+ className="TodayShell__sidebar TodayShell__drawer outline-none"
+ data-open={sidebarVisible}
+ aria-label={PANE_LABELS[activePane]}
+ aria-hidden={!sidebarVisible}
+ {...(sidebarVisible ? {} : { inert: '' })}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ width: sidebarWidth }}
+ >
+ {pane}
+ <TodaySidebarFooter />
+ </aside>
+ </>
+ ) : (
+ sidebarVisible && (
+ <aside
+ ref={sidebarRef}
+ className="TodayShell__sidebar relative"
+ aria-label={PANE_LABELS[activePane]}
+ // eslint-disable-next-line react/forbid-dom-props
+ style={{ width: sidebarWidth }}
+ >
+ {pane}
+ <TodaySidebarFooter />
+ <Resizer {...resizerLogicProps} className="z-2" offset={0} />
+ </aside>
+ )
)}
{/* Mounted here so the sidebar and the spaces page open the same dialog. */}
<NewSpaceDialog />
diff --git a/frontend/src/layout/today/todayShellLogic.test.ts b/frontend/src/layout/today/todayShellLogic.test.ts
index 8ad33ecd1c6b..0d9d45f1447f 100644
--- a/frontend/src/layout/today/todayShellLogic.test.ts
+++ b/frontend/src/layout/today/todayShellLogic.test.ts
@@ -1,5 +1,8 @@
import { router } from 'kea-router'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+
import { initKeaTests } from '~/test/init'
import { TODAY_RAIL_WIDTH, TODAY_SIDEBAR_MAX_WIDTH, railPaneForPath, todayShellLogic } from './todayShellLogic'
@@ -62,4 +65,31 @@ describe('todayShellLogic', () => {
logic.actions.setSidebarOpen(false)
expect(logic.values.leftNavWidth).toBe(TODAY_RAIL_WIDTH)
})
+ it('keeps the rail on narrow windows and opens the sidebar as a drawer that closes on navigation', () => {
+ const originalWidth = window.innerWidth
+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: 800 })
+ try {
+ featureFlagLogic.mount()
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.TODAY_RAIL_NAV], {
+ [FEATURE_FLAGS.TODAY_RAIL_NAV]: true,
+ })
+ const logic = todayShellLogic()
+ logic.mount()
+
+ expect(logic.values.todayRailEnabled).toBe(true)
+ expect(logic.values.leftNavWidth).toBe(TODAY_RAIL_WIDTH)
+ expect(logic.values.sidebarVisible).toBe(false)
+
+ logic.actions.setSidebarOpen(false)
+ logic.actions.pickPane('library')
+ expect(logic.values.sidebarVisible).toBe(true)
+ expect(logic.values.sidebarOpen).toBe(false)
+ expect(logic.values.leftNavWidth).toBe(TODAY_RAIL_WIDTH)
+
+ router.actions.push('/project/1/insights/abc')
+ expect(logic.values.sidebarVisible).toBe(false)
+ } finally {
+ Object.defineProperty(window, 'innerWidth', { configurable: true, value: originalWidth })
+ }
+ })
})
diff --git a/frontend/src/layout/today/todayShellLogic.ts b/frontend/src/layout/today/todayShellLogic.ts
index 6520e2a93760..9d6f46728694 100644
--- a/frontend/src/layout/today/todayShellLogic.ts
+++ b/frontend/src/layout/today/todayShellLogic.ts
@@ -1,6 +1,7 @@
import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { router } from 'kea-router'
import type { LocationChangedPayload } from 'kea-router/lib/types'
+import { subscriptions } from 'kea-subscriptions'
import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
@@ -57,9 +58,11 @@ export interface todayShellLogicValues {
mobileLayout: boolean // navigationLogic
activePane: TodayRailPane
leftNavWidth: number
+ mobileSidebarOpen: boolean
pickedPane: TodayRailPane | null
routePane: TodayRailPane | null
sidebarOpen: boolean
+ sidebarVisible: boolean
sidebarWidth: number
todayRailEnabled: boolean
}
@@ -90,6 +93,9 @@ export interface todayShellLogicActions {
pickPane: (pane: TodayRailPane) => {
pane: TodayRailPane
}
+ setMobileSidebarOpen: (open: boolean) => {
+ open: boolean
+ }
setSidebarOpen: (open: boolean) => {
open: boolean
}
@@ -106,8 +112,9 @@ export interface todayShellLogicMeta {
__keaTypeGenInternalSelectorTypes: {
routePane: (location: { hash: string; pathname: string; search: string }) => TodayRailPane | null
activePane: (pickedPane: TodayRailPane | null, routePane: TodayRailPane | null) => TodayRailPane
- leftNavWidth: (sidebarOpen: boolean, sidebarWidth: number) => number
- todayRailEnabled: (featureFlags: FeatureFlagsSet, mobileLayout: boolean) => boolean
+ leftNavWidth: (sidebarOpen: boolean, sidebarWidth: number, mobileLayout: boolean) => number
+ sidebarVisible: (mobileLayout: boolean, mobileSidebarOpen: boolean, sidebarOpen: boolean) => boolean
+ todayRailEnabled: (featureFlags: FeatureFlagsSet) => boolean
}
}
@@ -126,6 +133,7 @@ export const todayShellLogic = kea<todayShellLogicType>([
})),
actions({
pickPane: (pane: TodayRailPane) => ({ pane }),
+ setMobileSidebarOpen: (open: boolean) => ({ open }),
setSidebarOpen: (open: boolean) => ({ open }),
setSidebarWidth: (width: number) => ({ width }),
toggleSidebar: true,
@@ -144,8 +152,13 @@ export const todayShellLogic = kea<todayShellLogicType>([
{ persist: true },
{
setSidebarOpen: (_, { open }) => open,
- toggleSidebar: (state) => !state,
- pickPane: () => true,
+ },
+ ],
+ mobileSidebarOpen: [
+ false,
+ {
+ setMobileSidebarOpen: (_, { open }) => open,
+ locationChanged: () => false,
},
],
// The resizer persists the width itself. This copy lets the app layout size the main column from it.
@@ -162,17 +175,46 @@ export const todayShellLogic = kea<todayShellLogicType>([
pickedPane ?? routePane ?? 'home',
],
leftNavWidth: [
- (s) => [s.sidebarOpen, s.sidebarWidth],
- (sidebarOpen: boolean, sidebarWidth: number): number => TODAY_RAIL_WIDTH + (sidebarOpen ? sidebarWidth : 0),
+ (s) => [s.sidebarOpen, s.sidebarWidth, s.mobileLayout],
+ (sidebarOpen: boolean, sidebarWidth: number, mobileLayout: boolean): number =>
+ TODAY_RAIL_WIDTH + (sidebarOpen && !mobileLayout ? sidebarWidth : 0),
+ ],
+ sidebarVisible: [
+ (s) => [s.mobileLayout, s.mobileSidebarOpen, s.sidebarOpen],
+ (mobileLayout: boolean, mobileSidebarOpen: boolean, sidebarOpen: boolean): boolean =>
+ mobileLayout ? mobileSidebarOpen : sidebarOpen,
],
- // The rail has no overlay mode, so narrow windows keep the regular navigation.
todayRailEnabled: [
- (s) => [s.featureFlags, s.mobileLayout],
- (featureFlags: FeatureFlagsSet, mobileLayout: boolean): boolean =>
- !!featureFlags[FEATURE_FLAGS.TODAY_RAIL_NAV] && !mobileLayout,
+ (s) => [s.featureFlags],
+ (featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.TODAY_RAIL_NAV],
],
}),
- listeners(({ values }) => ({
+ subscriptions(({ actions }) => ({
+ mobileLayout: () => actions.setMobileSidebarOpen(false),
+ })),
+ listeners(({ actions, values, cache }) => ({
+ toggleSidebar: () => {
+ if (values.mobileLayout) {
+ actions.setMobileSidebarOpen(!values.mobileSidebarOpen)
+ } else {
+ actions.setSidebarOpen(!values.sidebarOpen)
+ }
+ },
+ setMobileSidebarOpen: ({ open }) => {
+ if (!open) {
+ cache.disposables.dispose('drawerEscape')
+ return
+ }
+ cache.disposables.add(() => {
+ const onKeyDown = (event: KeyboardEvent): void => {
+ if (event.key === 'Escape' && values.mobileSidebarOpen) {
+ actions.setMobileSidebarOpen(false)
+ }
+ }
+ window.addEventListener('keydown', onKeyDown)
+ return () => window.removeEventListener('keydown', onKeyDown)
+ }, 'drawerEscape')
+ },
pickPane: ({ pane }) => {
// pinned: analytics event name and property. Renaming them breaks dashboards.
posthog.capture('today rail pane picked', { pane })
@@ -182,6 +224,11 @@ export const todayShellLogic = kea<todayShellLogicType>([
if (pane === 'library' && values.routePane !== 'library') {
router.actions.push(urls.library())
}
+ if (values.mobileLayout) {
+ actions.setMobileSidebarOpen(true)
+ } else {
+ actions.setSidebarOpen(true)
+ }
},
})),
])
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
index 503034a7decf..0749b036adb4 100644
--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx
+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx
@@ -328,3 +328,14 @@ export const ToolsPane: Story = {
await userEvent.click(await within(canvasElement).findByLabelText('Tools'))
},
}
+
+export const NarrowWindow: Story = {
+ parameters: { testOptions: { viewport: { width: 800, height: 900 } } },
+}
+
+export const NarrowWindowWithSidebar: Story = {
+ parameters: { testOptions: { viewport: { width: 800, height: 900 } } },
+ play: async ({ canvasElement }) => {
+ await userEvent.click(await within(canvasElement).findByLabelText('Home'))
+ },
+}