As in the picture above, some file item is outdent as the too long filename.
export const FileTreeFile = ({
path,
name,
icon,
className,
children,
...props
}: FileTreeFileProps) => {
const { selectedPath, onSelect } = useContext(FileTreeContext);
const isSelected = selectedPath === path;
const handleClick = useCallback(() => {
onSelect?.(path);
}, [onSelect, path]);
const handleKeyDown = useCallback(
(e: React.KeyboardEvent) => {
if (e.key === "Enter" || e.key === " ") {
onSelect?.(path);
}
},
[onSelect, path]
);
const fileContextValue = useMemo(() => ({ name, path }), [name, path]);
return (
<FileTreeFileContext.Provider value={fileContextValue}>
<div
className={cn(
"flex cursor-pointer items-center gap-1 rounded px-2 py-1 transition-colors hover:bg-muted/50",
isSelected && "bg-muted",
className
)}
onClick={handleClick}
onKeyDown={handleKeyDown}
role="treeitem"
tabIndex={0}
{...props}
>
{children ?? (
<>
{/* Spacer for alignment */}
<span className="size-4 shrink-0" /> // <- add shrink-0 here
<FileTreeIcon>
{icon ?? <FileIcon className="size-4 text-muted-foreground" />}
</FileTreeIcon>
<FileTreeName>{name}</FileTreeName>
</>
)}
</div>
</FileTreeFileContext.Provider>
);
};
As in the picture above, some file item is outdent as the too long filename.
The solution is to add a
shrink-0to the indent element ofFileTreeFile: