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.

feat(ui): one hover card slides between nav rail items

Sidwebworks199a2f651d5a
diff --git a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
index b752cfd2b3..63b8b117b7 100644
--- a/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
+++ b/apps/erp/app/components/Layout/Navigation/PrimaryNavigation.tsx
@@ -169,6 +169,7 @@ const PrimaryNavigation = () => {
label={t`Customize`}
onClick={editMode.enterEditMode}
className={ACTION_HOVER}
+ data-hover-tone="accent"
/>
)}
</>
@@ -266,6 +267,7 @@ const NavigationSearchButton = () => {
openSearchModal();
}}
className={ACTION_HOVER}
+ data-hover-tone="accent"
trailing={
<ShortcutKey
shortcut={searchShortcut}
diff --git a/packages/react/src/NavRail.tsx b/packages/react/src/NavRail.tsx
index 3219652057..0b177ee383 100644
--- a/packages/react/src/NavRail.tsx
+++ b/packages/react/src/NavRail.tsx
@@ -79,6 +79,7 @@ export function NavRail({
const { pathname } = useLocation();
const [hovered, setHovered] = useState(false);
const navRef = useRef<HTMLElement>(null);
+ const hoverCardRef = useRef<HTMLSpanElement>(null);
const lastPointerType = useRef<string>();
const openTimer = useRef<ReturnType<typeof setTimeout>>();
const cancelHoverOpen = useCallback(() => {
@@ -86,6 +87,31 @@ export function NavRail({
openTimer.current = undefined;
}, []);
useEffect(() => cancelHoverOpen, [cancelHoverOpen]);
+
+ // One hover card for the whole rail, moved with a transform to the item
+ // under the pointer, so the highlight travels between items instead of
+ // each item fading its own. Written straight to the element: a hover must
+ // not re-render the rail.
+ const moveHoverCard = useCallback((item: HTMLElement | null) => {
+ const card = hoverCardRef.current;
+ const nav = navRef.current;
+ if (!card || !nav) return;
+ if (!item) {
+ card.style.opacity = "0";
+ return;
+ }
+ const top =
+ item.getBoundingClientRect().top -
+ nav.getBoundingClientRect().top +
+ nav.scrollTop;
+ // Entering the rail: appear on the item rather than slide in from
+ // wherever the card was last.
+ card.style.transitionProperty = card.style.opacity === "1" ? "" : "opacity";
+ card.style.transform = `translateY(${top}px)`;
+ card.dataset.tone = item.dataset.hoverTone ?? "";
+ card.style.opacity = "1";
+ }, []);
+
const [holds, setHolds] = useState(0);
const hold = useCallback(() => {
setHolds((n) => n + 1);
@@ -110,7 +136,10 @@ export function NavRail({
}, [disableHover]);
useEffect(() => {
cancelHoverOpen();
- if (hoverBlocked) return;
+ if (hoverBlocked) {
+ moveHoverCard(null);
+ return;
+ }
// Touch browsers leave `:hover` stuck on the last tapped element, so only
// a mouse's `:hover` counts.
const raf = requestAnimationFrame(() =>
@@ -120,7 +149,7 @@ export function NavRail({
)
);
return () => cancelAnimationFrame(raf);
- }, [hoverBlocked, cancelHoverOpen]);
+ }, [hoverBlocked, cancelHoverOpen, moveHoverCard]);
const content = (
<NavRailHoldContext.Provider value={hold}>
@@ -176,6 +205,7 @@ export function NavRail({
ref={navRef}
data-state={state}
data-floating={!pinned && hovered}
+ data-sliding-hover=""
className={cn(
"absolute inset-y-0 left-0 bg-background py-2 group",
"w-14 data-[state=expanded]:w-[13rem]",
@@ -187,6 +217,15 @@ export function NavRail({
onPointerDown={(event) => {
lastPointerType.current = event.pointerType;
}}
+ // The gaps between items are not items: the card stays where it is
+ // while the pointer crosses one, and only leaves with the pointer.
+ onPointerOver={(event) => {
+ if (hoverBlocked || event.pointerType !== "mouse") return;
+ const item = (event.target as HTMLElement).closest<HTMLElement>(
+ "[data-nav-item]"
+ );
+ if (item) moveHoverCard(item);
+ }}
// Mouse only: a tap on a touch tablet must not expand the rail.
onPointerMove={(event) => {
lastPointerType.current = event.pointerType;
@@ -210,8 +249,18 @@ export function NavRail({
if (document.body.style.pointerEvents === "none") return;
cancelHoverOpen();
setHovered(false);
+ moveHoverCard(null);
}}
>
+ <span
+ ref={hoverCardRef}
+ aria-hidden
+ className={cn(
+ "pointer-events-none absolute left-2 right-2 top-0 h-10 rounded-md opacity-0",
+ "bg-active/60 data-[tone=accent]:bg-accent",
+ "transition-[transform,opacity,background-color] duration-150 ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:transition-none"
+ )}
+ />
{content}
</nav>
</div>
@@ -267,12 +316,15 @@ export const NavRailItem = forwardRef<HTMLButtonElement, NavRailItemProps>(
ref={ref}
type={asChild ? undefined : "button"}
aria-label={label}
+ data-nav-item=""
{...props}
className={cn(
navRailItemClasses,
isActive
? "bg-active text-active-foreground dark:shadow-button-base"
- : "hover:bg-active/60 hover:text-active-foreground",
+ : // On the desktop rail one card slides between the hovered
+ // items instead; the active item keeps its own background.
+ "hover:bg-active/60 hover:text-active-foreground group-data-[sliding-hover]:hover:bg-transparent",
className
)}
>