Prerequisites
- I have searched for duplicate or closed feature requests
- I have read the contributing guidelines
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
4Hi! 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.
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
Implemented the requested flattenedSegmentsTruncation option and opened PR #1068 for review.
PR: #1068
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.