Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions apps/code/src/renderer/features/sidebar/components/SidebarItem.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Tooltip } from "@components/ui/Tooltip";
import { Button, cn } from "@posthog/quill";
import { useCallback, useRef, useState } from "react";
import type { SidebarItemAction } from "../types";

const INDENT_SIZE = 8;
Expand Down Expand Up @@ -34,6 +36,34 @@ export function SidebarItem({
endContent,
disabled,
}: SidebarItemProps) {
const labelRef = useRef<HTMLSpanElement>(null);
const [showLabelTooltip, setShowLabelTooltip] = useState(false);
const canShowLabelTooltip =
typeof label === "string" || typeof label === "number";

const handleLabelMouseEnter = useCallback(() => {
const el = labelRef.current;
if (el && el.scrollWidth > el.clientWidth) {
setShowLabelTooltip(true);
}
}, []);

const handleLabelMouseLeave = useCallback(() => {
setShowLabelTooltip(false);
}, []);

const labelSpan = (
// biome-ignore lint/a11y/noStaticElementInteractions: hover handlers only drive a visual tooltip for truncated labels
<span
ref={labelRef}
className="min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap"
onMouseEnter={canShowLabelTooltip ? handleLabelMouseEnter : undefined}
onMouseLeave={canShowLabelTooltip ? handleLabelMouseLeave : undefined}
>
{label}
</span>
);

return (
<Button
type="button"
Expand All @@ -55,9 +85,13 @@ export function SidebarItem({
{icon ? <span className="flex shrink-0 items-center">{icon}</span> : null}
<span className="flex min-w-0 flex-1 flex-col overflow-hidden">
<span className="flex items-center gap-1" style={{ height: "18px" }}>
<span className="min-w-0 flex-1 overflow-hidden text-ellipsis whitespace-nowrap">
{label}
</span>
{canShowLabelTooltip ? (
<Tooltip content={label} open={showLabelTooltip} side="top">
{labelSpan}
</Tooltip>
) : (
labelSpan
)}
{endContent}
</span>
{subtitle && (
Expand Down
Loading