Skip to content
Merged
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion packages/components/react/src/core/FileTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function File({ file: { depth, name }, onClick, selected }: FileProps) {
'text-tk-elements-fileTree-file-iconColorSelected': selected,
})}
onClick={onClick}
aria-pressed={selected}
>
{name}
</NodeButton>
Expand All @@ -162,14 +163,16 @@ interface ButtonProps {
children: ReactNode;
className?: string;
onClick?: () => void;
'aria-pressed'?: boolean;
}

function NodeButton({ depth, iconClasses, onClick, className, children }: ButtonProps) {
function NodeButton({ depth, iconClasses, onClick, className, 'aria-pressed': ariaPressed, children }: ButtonProps) {
return (
<button
className={`flex items-center gap-2 w-full pr-2 border-2 border-transparent text-faded ${className ?? ''}`}
style={{ paddingLeft: `${12 + depth * NODE_PADDING_LEFT}px` }}
onClick={() => onClick?.()}
aria-pressed={ariaPressed === true ? 'true' : undefined}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't 100% correct either as these are not toggle buttons, but it's better than nothing. Proper way would be to throw these buttons away and create a proper tree: https://www.w3.org/WAI/ARIA/apg/patterns/treeview/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current representation though is much more efficient and much simpler than a tree.

Copy link
Member Author

@AriPerkkio AriPerkkio Aug 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler sure, but not accessible as it's not semantic. Assistive technologies are unable to detect these as file trees - it's just multiple buttons, not even a list. If we some day want to make this accessible, we should check how vscode.dev for example does this.

image

>
<div className={classNames('scale-120 shrink-0', iconClasses)}></div>
<span>{children}</span>
Expand Down