Skip to content

Commit 61a93e2

Browse files
TreeView: Add nesting indicator lines (#2350)
* Add TreeView docs * Update TreeView props * Scaffold treeview markup * Add TreeView to drafts * Add comment * Track item levels * Add TreeView stories * Update TreeView docs * Update TreeView markup * Create curly-birds-argue.md * Fix examples * Update src/TreeView/TreeView.tsx * Update docs/content/TreeView.mdx * Add some tests * Implement arrow key navigation * Fix arrow left * Set up aria-activedescendant Co-authored-by: Eric Bailey <[email protected]> * Display focus ring on active descendant * Use arrow key to change active descendant * Handle expand/collapse with arrow keys * Fix lint error * Add up and down arrow key test * Prevent default when moving focus with arrow keys * Open links in same tab by default * Add test for right arrow key expand * Add defaultExpanded prop * Test left arrow key collapse * Reorganize tests * Create neat-squids-cheat.md * Add more tests * Implement home and end key behavior * Update active descendant on click * Remove focus state * Remove focus state from context * Test enter and space keys * Update focus style * Remove Space key behavior * Wrap test cases with themeprovider * Add test for link item * Update urls * Add indicator lines for each nested level * Create heavy-pets-own.md * Create LevelIndicatorLines component * Remove transitions for now Co-authored-by: Eric Bailey <[email protected]>
1 parent 68c4980 commit 61a93e2

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

.changeset/heavy-pets-own.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Adds lines to indicate the depth of items in a TreeView

src/TreeView/TreeView.tsx

+36-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ const Item: React.FC<TreeViewItemProps> = ({
339339
color: 'fg.default',
340340
borderRadius: 2,
341341
cursor: 'pointer',
342-
transition: 'background 33.333ms linear',
343342
'&:hover': {
344343
backgroundColor: 'actionListItem.default.hoverBg'
345344
},
@@ -361,6 +360,9 @@ const Item: React.FC<TreeViewItemProps> = ({
361360
}
362361
}}
363362
>
363+
<Box sx={{gridArea: 'spacer', display: 'flex'}}>
364+
<LevelIndicatorLines level={level} />
365+
</Box>
364366
{hasSubTree ? (
365367
<Box
366368
onClick={event => {
@@ -405,6 +407,39 @@ const Item: React.FC<TreeViewItemProps> = ({
405407
)
406408
}
407409

410+
/** Lines to indicate the depth of an item in a TreeView */
411+
const LevelIndicatorLines: React.FC<{level: number}> = ({level}) => {
412+
return (
413+
<Box sx={{width: '100%', display: 'flex'}}>
414+
{Array.from({length: level - 1}).map((_, index) => (
415+
<Box
416+
key={index}
417+
sx={{
418+
width: '100%',
419+
height: '100%',
420+
borderRight: '1px solid',
421+
422+
// On devices without hover, the nesting indicator lines
423+
// appear at all times.
424+
borderColor: 'border.subtle',
425+
426+
// On devices with :hover support, the nesting indicator lines
427+
// fade in when the user mouses over the entire component,
428+
// or when there's focus inside the component. This makes
429+
// sure the component remains simple when not in use.
430+
'@media (hover: hover)': {
431+
borderColor: 'transparent',
432+
'[role=tree]:hover &, [role=tree]:focus &': {
433+
borderColor: 'border.subtle'
434+
}
435+
}
436+
}}
437+
/>
438+
))}
439+
</Box>
440+
)
441+
}
442+
408443
// ----------------------------------------------------------------------------
409444
// TreeView.LinkItem
410445

0 commit comments

Comments
 (0)