#1027

Feature: flattenEmptyDirectories: support end-truncation for the whole flattened path instead of per-segment truncation

Openlucifer-yfopened 3mo ago

Prerequisites

Proposal

Currently when
flattenEmptyDirectories: true is enabled, each path segment is individually wrapped in a Truncate component, resulting in display
like:

a... / b... / c... / dd... / ...

We'd like to support an option to truncate the whole flattened path at the end, like:

aaa / bbb / ccc /...

This is more readable and matches
how most file explorers (e.g. VS
Code) handle deep nested paths.

Proposed API:

useFileTree({                      
  flattenEmptyDirectories: true,   
  flattenedSegmentsTruncation:   
'end', // 'per-segment' (default) |
 'end'                             
})      

Or alternatively a CSS variable /
data attribute that consumers can
use to override the truncation
strategy via unsafeCSS.

Motivation and context

When flattenEmptyDirectories: true is enabled and the tree is rendered in a narrow container (e.g. a
sidebar panel pushed to the right
edge), the per-segment truncation
produces a very poor visual result — every segment gets clipped
individually, leaving a string of disconnected ellipses like a... / b... / c... / dd... / .... This makes the path nearly unreadable and wastes space with repeated ... markers.

VS Code handles this well by truncating the entire flattened path as a single string at the end (aaa / bbb / ccc /...), which keeps as much of the path visible as
possible and is far easier to scan at a glance. Supporting end-truncation for the whole path
would bring @pierre/trees in line with this established UX pattern and significantly improve usability in space-constrained layouts.

Activity

4
AbarnaaSree2mo ago

Hi! I'd like to work on this feature if it's still available. My plan is to add the proposed flattenedSegmentsTruncation option while preserving the current per-segment behavior as the default, and update the tests and documentation. Please let me know if that approach aligns with what you're have in mind.

AbarnaaSree2mo ago

Hi! I'd like to work on this feature if it's still available. My plan is to add the proposed flattenedSegmentsTruncation option while preserving the current per-segment behavior as the default, and update the tests and documentation. Please let me know if that approach aligns with what you're have in mind.

JoeJoeflyn2mo ago

Hi! I'd like to work on this feature if it's still available. My plan is to add the proposed flattenedSegmentsTruncation option while preserving the current per-segment behavior as the default, and update the tests and documentation. Please let me know if that approach aligns with what you're have in mind.

just do it, no one claims it

AbarnaaSree2mo ago

Implemented the requested flattenedSegmentsTruncation option and opened PR #1068 for review.

PR: #1068