Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(nav): tapping a menu on a collapsed rail no longer expands it

aashu2b3d0921f016
diff --git a/packages/react/AGENTS.md b/packages/react/AGENTS.md
index f7a613c2a5..18358d3da6 100644
--- a/packages/react/AGENTS.md
+++ b/packages/react/AGENTS.md
@@ -41,7 +41,7 @@ import { Button, Card, HStack, VStack, IconButton, cn } from "@carbon/react";
- **Choice screens**: `ChoiceCardGroup` (card radios, `autoFocus` focuses the selected card) and `RadioGroupButton` (radio styled as a secondary Button) give one tab stop + arrow-key select; Enter stays free for the screen's continue action
- **Layout**: `VStack` / `HStack` with numeric `spacing` prop (maps to `space-y-*`/`space-x-*`)
- **Overlays**: `Drawer`, `Modal`, `ModalDrawer` (unified drawer/modal), `BottomSheet`, `Popover`
-- **App nav**: `NavRail` is the primary left nav of both the ERP and MES shells (56px icon rail, expands after a 150ms mouse hover or when pinned via `SidebarProvider`/⌘B, left drawer below md that closes itself on navigation). Optional `header` (use `NavRailBrand` for a logo + name) and `footer` slots; `NavRailGroup` adds a titled section that shows as a divider while collapsed. Entries are `NavRailItem` (a button, or `asChild` for a trigger/link) and `NavRailLink`; `label` is a string and doubles as the accessible name. A Radix menu/popover opened from a `NavRailItem` holds the rail expanded until it closes. Render inside `SidebarProvider`; the shadcn-style `Sidebar*` primitives remain for other layouts
+- **App nav**: `NavRail` is the primary left nav of both the ERP and MES shells (56px icon rail, expands after a 150ms mouse hover or when pinned via `SidebarProvider`/⌘B, left drawer below md that closes itself on navigation). Optional `header` (use `NavRailBrand` for a logo + name) and `footer` slots; `NavRailGroup` adds a titled section that shows as a divider while collapsed. Entries are `NavRailItem` (a button, or `asChild` for a trigger/link) and `NavRailLink`; `label` is a string and doubles as the accessible name. A Radix menu/popover opened from a `NavRailItem` keeps the rail as it was (open or collapsed) until it closes. Render inside `SidebarProvider`; the shadcn-style `Sidebar*` primitives remain for other layouts
- **Data**: `Table` (TanStack), chart components via sub-exports (`@carbon/react/Chart`)
- **Rich text**: `@carbon/react/Editor` and `@carbon/react/RichText` (wraps `@carbon/tiptap`)
- **Error boundary**: `@carbon/react/ErrorBoundary` — `RootErrorBoundary` (drop-in root `ErrorBoundary` for RR v7 that maps 404 / other HTTP / thrown `Error` to a styled screen) plus its parts (`ErrorScreen`, `GlitchHeading`, `StatusReadout`, `MagneticLink`, `NoiseOverlay`). Wrap it in the app's `Document` and pass `env` so `window.env` is set (the client crashes hydration otherwise). Copy is intentionally hardcoded English, not i18n.
diff --git a/packages/react/src/NavRail.tsx b/packages/react/src/NavRail.tsx
index 57d0f07970..9b7d96cfca 100644
--- a/packages/react/src/NavRail.tsx
+++ b/packages/react/src/NavRail.tsx
@@ -47,7 +47,8 @@ export const navRailItemClasses = [
// A pointer only passing over the rail (on its way to the page) shouldn't open it.
const HOVER_OPEN_DELAY_MS = 150;
-// Lets an item keep the rail open while a menu or popover it triggered is open.
+// Lets an item freeze the rail as it is (open or collapsed) while a menu or
+// popover it triggered is open, so a tap on a collapsed rail never opens it.
const NavRailHoldContext = createContext<(() => () => void) | null>(null);
export function NavRail({
@@ -69,6 +70,7 @@ export function NavRail({
const { pathname } = useLocation();
const [hovered, setHovered] = useState(false);
const navRef = useRef<HTMLElement>(null);
+ const lastPointerType = useRef<string>();
const openTimer = useRef<ReturnType<typeof setTimeout>>();
const cancelHoverOpen = useCallback(() => {
clearTimeout(openTimer.current);
@@ -100,8 +102,13 @@ export function NavRail({
useEffect(() => {
cancelHoverOpen();
if (hoverBlocked) return;
+ // Touch browsers leave `:hover` stuck on the last tapped element, so only
+ // a mouse's `:hover` counts.
const raf = requestAnimationFrame(() =>
- setHovered(navRef.current?.matches(":hover") ?? false)
+ setHovered(
+ lastPointerType.current === "mouse" &&
+ (navRef.current?.matches(":hover") ?? false)
+ )
);
return () => cancelAnimationFrame(raf);
}, [hoverBlocked, cancelHoverOpen]);
@@ -140,8 +147,7 @@ export function NavRail({
);
}
- const state =
- forceExpanded || open || hovered || holds > 0 ? "expanded" : "collapsed";
+ const state = forceExpanded || open || hovered ? "expanded" : "collapsed";
return (
// The wrapper (not just the inner nav) grows on expand, so the rail pushes
@@ -163,8 +169,12 @@ export function NavRail({
"flex flex-col justify-between",
"hide-scrollbar overflow-y-auto scrollbar-thin scrollbar-track-transparent scrollbar-thumb-accent"
)}
+ onPointerDown={(event) => {
+ lastPointerType.current = event.pointerType;
+ }}
// Mouse only: a tap on a touch tablet must not expand the rail.
onPointerMove={(event) => {
+ lastPointerType.current = event.pointerType;
if (hoverBlocked || hovered || openTimer.current) return;
if (event.pointerType !== "mouse") return;
openTimer.current = setTimeout(() => {