Skip to content

Commit 67f0800

Browse files
authored
TreeView single item nesting (#1937)
* add class for singleton nesting * Create cold-ducks-deny.md
1 parent c53ecdf commit 67f0800

File tree

5 files changed

+64
-5
lines changed

5 files changed

+64
-5
lines changed

.changeset/cold-ducks-deny.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": minor
3+
---
4+
5+
TreeView single item nesting

docs/src/stories/ui-patterns/ActionList/ActionListItem.stories.jsx

+13-3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ export default {
167167
category: 'HTML'
168168
}
169169
},
170+
treeItemSingleton: {
171+
defaultValue: false,
172+
control: {type: 'boolean'},
173+
table: {
174+
category: 'CSS'
175+
}
176+
},
170177
ariaDisabled: {
171178
defaultValue: false,
172179
control: {type: 'boolean'},
@@ -243,7 +250,8 @@ export const ListItemTemplate = ({
243250
treeitem,
244251
ariaSetSize,
245252
ariaPosInset,
246-
menuItem
253+
menuItem,
254+
treeItemSingleton
247255
}) => {
248256
const [isChecked, itemIsChecked] = useToggle()
249257
const itemStyle = {
@@ -256,7 +264,8 @@ export const ListItemTemplate = ({
256264
ariaCurrent && 'ActionList-item--navActive',
257265
subItem && `ActionList-item--subItem`,
258266
hasSubItem && `ActionList-item--hasSubItem`,
259-
variant && `${variant}`
267+
variant && `${variant}`,
268+
treeitem && treeItemSingleton && `ActionList-item--singleton`
260269
)}
261270
aria-level={ariaLevel ? `${ariaLevel}` : undefined}
262271
aria-setsize={ariaSetSize ? `${ariaSetSize}` : undefined}
@@ -466,5 +475,6 @@ Playground.decorators = [
466475
)
467476
]
468477
Playground.args = {
469-
truncateItem: false
478+
truncateItem: false,
479+
treeItemSingleton: false
470480
}

docs/src/stories/ui-patterns/ActionList/ActionListTree.stories.jsx

+25
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ const trailingVisual = `<svg aria-hidden="true" role="img" class="color-fg-atten
5050
export const ActionListTreeViewTemplate = ({showGroupIcon, showSubItemIcon, text, truncateItem}) => (
5151
<ListTemplate ariaLabel="Some description" role="tree" variant="ActionList--tree">
5252
<>
53+
<ListItemTemplate
54+
truncateItem={truncateItem}
55+
ariaLevel="1"
56+
ariaSetSize="1"
57+
ariaPosInset="1"
58+
treeitem
59+
text={text}
60+
href="/"
61+
leadingVisual={showSubItemIcon && file}
62+
trailingVisual={trailingVisual}
63+
treeItemSingleton
64+
/>
5365
<TreeViewListItemCollapsibleTemplate
5466
text="level 1"
5567
leadingVisual={showGroupIcon && folder}
@@ -59,6 +71,7 @@ export const ActionListTreeViewTemplate = ({showGroupIcon, showSubItemIcon, text
5971
ariaPosInset="2"
6072
collapsePosition={0}
6173
containsSubItem
74+
containsActiveSubItem
6275
>
6376
<ListTemplate listType="nested">
6477
<ListItemTemplate
@@ -150,6 +163,18 @@ export const ActionListTreeViewTemplate = ({showGroupIcon, showSubItemIcon, text
150163
</TreeViewListItemCollapsibleTemplate>
151164
</ListTemplate>
152165
</TreeViewListItemCollapsibleTemplate>
166+
<ListItemTemplate
167+
truncateItem={truncateItem}
168+
ariaLevel="1"
169+
ariaSetSize="1"
170+
ariaPosInset="1"
171+
treeitem
172+
text={text}
173+
href="/"
174+
leadingVisual={showSubItemIcon && file}
175+
trailingVisual={trailingVisual}
176+
treeItemSingleton
177+
/>
153178
</>
154179
</ListTemplate>
155180
)

docs/src/stories/ui-patterns/ActionList/TreeViewListItemCollapsible.stories.jsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ export default {
157157
table: {
158158
category: 'HTML'
159159
}
160+
},
161+
containsActiveSubItem: {
162+
defaultValue: false,
163+
control: {type: 'boolean'},
164+
table: {
165+
category: 'CSS'
166+
}
160167
}
161168
}
162169
}
@@ -177,15 +184,20 @@ export const TreeViewListItemCollapsibleTemplate = ({
177184
ariaSetSize,
178185
ariaPosInset,
179186
ariaLevel,
180-
ariaDisabled
187+
ariaDisabled,
188+
containsActiveSubItem
181189
}) => {
182190
const [isCollapsed, itemIsCollapsed] = useToggle()
183191
const itemStyle = {
184192
'--ActionList-tree-depth': `${ariaLevel}`
185193
}
186194
return (
187195
<li
188-
className={clsx('ActionList-item', containsSubItem && `ActionList-item--hasSubItem`)}
196+
className={clsx(
197+
'ActionList-item',
198+
containsSubItem && `ActionList-item--hasSubItem`,
199+
containsActiveSubItem && `ActionList-item--hasActiveSubItem`
200+
)}
189201
onClick={itemIsCollapsed}
190202
id={id}
191203
aria-disabled={ariaDisabled ? 'true' : undefined}

src/actionlist/action-list-tree.scss

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
}
3434

3535
.ActionList-item {
36+
// class for single tree items not within a group
37+
&.ActionList-item--singleton {
38+
.ActionList-content {
39+
padding-left: $spacer-5;
40+
}
41+
}
42+
3643
// start: copy from ActionList proper- backwards compatible for treeview with different markup structure
3744
&[aria-expanded] {
3845
.ActionList--subGroup {

0 commit comments

Comments
 (0)