UI Library for Design Engineers. Animated components and effects you can copy and paste into your apps. Free. Open Source.
fix: add filetree accessibility fix (#448)
Dillion Vermab6401f01c0e4
diff --git a/registry/default/example/file-tree-demo.tsx b/registry/default/example/file-tree-demo.tsxindex 096c0576..fbfeb38d 100644--- a/registry/default/example/file-tree-demo.tsx+++ b/registry/default/example/file-tree-demo.tsx@@ -4,7 +4,7 @@ export default function FileTreeDemo() {return (<div className="relative flex h-[300px] w-1/2 flex-col items-center justify-center overflow-hidden rounded-lg border bg-background md:shadow-xl"><Tree- className="p-2 overflow-hidden rounded-md bg-background"+ className="overflow-hidden rounded-md bg-background p-2"initialSelectedId="7"initialExpandedItems={["1",diff --git a/registry/default/magicui/file-tree.tsx b/registry/default/magicui/file-tree.tsxindex 2a95a62b..4bff8963 100644--- a/registry/default/magicui/file-tree.tsx+++ b/registry/default/magicui/file-tree.tsx@@ -1,5 +1,7 @@"use client";+import * as AccordionPrimitive from "@radix-ui/react-accordion";+import { FileIcon, FolderIcon, FolderOpenIcon } from "lucide-react";import React, {createContext,forwardRef,@@ -8,12 +10,10 @@ import React, {useEffect,useState,} from "react";-import * as AccordionPrimitive from "@radix-ui/react-accordion";-import { FileIcon, FolderIcon, FolderOpenIcon } from "lucide-react";-import { cn } from "@/lib/utils";import { Button } from "@/components/ui/button";import { ScrollArea } from "@/components/ui/scroll-area";+import { cn } from "@/lib/utils";type TreeViewElement = {id: string;@@ -155,7 +155,7 @@ const Tree = forwardRef<HTMLDivElement, TreeViewProps>(<div className={cn("size-full", className)}><ScrollArearef={ref}- className="h-full relative px-2"+ className="relative h-full px-2"dir={dir as Direction}><AccordionPrimitive.Root@@ -191,7 +191,7 @@ const TreeIndicator = forwardRef<dir={direction}ref={ref}className={cn(- "h-full w-px bg-muted absolute left-1.5 rtl:right-1.5 py-3 rounded-md hover:bg-slate-300 duration-300 ease-in-out",+ "absolute left-1.5 h-full w-px rounded-md bg-muted py-3 duration-300 ease-in-out hover:bg-slate-300 rtl:right-1.5",className,)}{...props}@@ -241,11 +241,11 @@ const Folder = forwardRef<<AccordionPrimitive.Item{...props}value={value}- className="relative overflow-hidden h-full "+ className="relative h-full overflow-hidden"><AccordionPrimitive.TriggerclassName={cn(- `flex items-center gap-1 text-sm rounded-md`,+ `flex items-center gap-1 rounded-md text-sm`,className,{"bg-muted rounded-md": isSelect && isSelectable,@@ -261,12 +261,12 @@ const Folder = forwardRef<: (closeIcon ?? <FolderIcon className="size-4" />)}<span>{element}</span></AccordionPrimitive.Trigger>- <AccordionPrimitive.Content className="text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down relative overflow-hidden h-full">+ <AccordionPrimitive.Content className="relative h-full overflow-hidden text-sm data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down">{element && indicator && <TreeIndicator aria-hidden="true" />}<AccordionPrimitive.Rootdir={direction}type="multiple"- className="flex flex-col gap-1 py-1 ml-5 rtl:mr-5 "+ className="ml-5 flex flex-col gap-1 py-1 rtl:mr-5 "defaultValue={expandedItems}value={expandedItems}onValueChange={(value) => {@@ -291,7 +291,7 @@ const File = forwardRef<isSelectable?: boolean;isSelect?: boolean;fileIcon?: React.ReactNode;- } & React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>+ } & React.ButtonHTMLAttributes<HTMLButtonElement>>(({@@ -309,27 +309,25 @@ const File = forwardRef<const { direction, selectedId, selectItem } = useTree();const isSelected = isSelect ?? selectedId === value;return (- <AccordionPrimitive.Item value={value} className="relative">- <AccordionPrimitive.Trigger- ref={ref}- {...props}- dir={direction}- disabled={!isSelectable}- aria-label="File"- className={cn(- "flex items-center gap-1 cursor-pointer text-sm pr-1 rtl:pl-1 rtl:pr-0 rounded-md duration-200 ease-in-out",- {- "bg-muted": isSelected && isSelectable,- },- isSelectable ? "cursor-pointer" : "opacity-50 cursor-not-allowed",- className,- )}- onClick={() => selectItem(value)}- >- {fileIcon ?? <FileIcon className="size-4" />}- {children}- </AccordionPrimitive.Trigger>- </AccordionPrimitive.Item>+ <button+ ref={ref}+ type="button"+ disabled={!isSelectable}+ className={cn(+ "flex w-fit items-center gap-1 rounded-md pr-1 text-sm duration-200 ease-in-out rtl:pl-1 rtl:pr-0",+ {+ "bg-muted": isSelected && isSelectable,+ },+ isSelectable ? "cursor-pointer" : "cursor-not-allowed opacity-50",+ direction === "rtl" ? "rtl" : "ltr",+ className,+ )}+ onClick={() => selectItem(value)}+ {...props}+ >+ {fileIcon ?? <FileIcon className="size-4" />}+ {children}+ </button>);},);@@ -371,7 +369,7 @@ const CollapseButton = forwardRef<return (<Buttonvariant={"ghost"}- className="h-8 w-fit p-1 absolute bottom-1 right-2"+ className="absolute bottom-1 right-2 h-8 w-fit p-1"onClick={expandedItems && expandedItems.length > 0? closeAll