Skip to content

Conversation

@colebemis
Copy link
Contributor

@colebemis colebemis commented Sep 19, 2022

Summary

Adds a current prop to TreeView.Item and TreeView.LinkItem to indicate which item is current (e.g., matches the user's current URL).

CleanShot 2022-09-19 at 12 06 16

<TreeView>
  <TreeView.LinkItem href="#1">Item 1</TreeView.LinkItem>
  <TreeView.LinkItem href="#2" current>Item 2</TreeView.LinkItem>
  <TreeView.LinkItem href="#3">Item 3</TreeView.LinkItem>
</TreeView>

Behavior

👉 Try it out

  • The path to the current item in a tree will be expanded by default
  • The current item will be expanded by default if it contains sub-items
  • The initial value of aria-activedescendant will be the current item (if there is a currrent item).
CleanShot.2022-09-19.at.12.10.17.mp4

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@colebemis colebemis marked this pull request as ready for review September 19, 2022 19:13
@colebemis colebemis requested review from a team and rezrah September 19, 2022 19:13
@colebemis
Copy link
Contributor Author

This PR is ready for review but let's not merge until we merge #2331

@colebemis colebemis requested review from mperrotti and removed request for rezrah September 19, 2022 19:21
@colebemis colebemis temporarily deployed to github-pages September 19, 2022 19:27 Inactive
Copy link
Contributor

@mperrotti mperrotti left a comment

Choose a reason for hiding this comment

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

current is set on the Button parent node, but it looks like aria-activedescendent is being set to the ID of the Button.tsx child node.

Screen Shot 2022-09-19 at 3 35 43 PM

toggle(event)
}
}}
sx={{
Copy link
Contributor

Choose a reason for hiding this comment

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

The value of sx could get reallly big as we start to get more into the styling. Maybe we could consider moving the style code into it's own file or at least outside of the component function's scope.

(Non-blocking for this PR)

@colebemis
Copy link
Contributor Author

current is set on the Button parent node, but it looks like aria-activedescendent is being set to the ID of the Button.tsx child node.

Screen Shot 2022-09-19 at 3 35 43 PM

Hmm, I'm not able to reproduce that:

CleanShot 2022-09-19 at 12 51 50

@mperrotti
Copy link
Contributor

@colebemis - I can't reproduce that anymore either. I think I must have unintentionally clicked Button.tsx


// If current item exists, set it as the active descendant
if (currentItem) {
setActiveDescendant(currentItem.id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it weird that aria-activedescendant updates on the parent, but aria-current does not move unless you manage it with state?

It seemed strange to me at first, but then I thought about it and was ok with it.

(non-blocking)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think of aria-current more as a "default value" for aria-activedescandant rather than state that should be kept in sync

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I update the code comments to make that more clear 👍

@colebemis colebemis temporarily deployed to github-pages September 19, 2022 21:31 Inactive
})

it('initializes aria-activedescendant to the first item by default', () => {
it('initializes aria-activedescendant to the current item by default', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Oh this is cool!

boxShadow: (theme: Theme) => `0 0 0 2px ${theme.colors.accent.emphasis}`
},
'[role=treeitem][aria-current=true] > &': {
bg: 'actionListItem.default.selectedBg',
Copy link
Member

Choose a reason for hiding this comment

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

This primitive looks tidied to the ActionList, I haven't seen many primitives like this so far in Primer. Is it temporary or any other reasoning behind using a component scoped primitive name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TreeView builds on ActionList styles so we're reusing some ActionList tokens/primitives here

Base automatically changed from treeview-arrow-keys to main September 20, 2022 16:15
@colebemis colebemis enabled auto-merge (squash) September 20, 2022 16:23
@colebemis colebemis temporarily deployed to github-pages September 20, 2022 16:29 Inactive
@colebemis colebemis temporarily deployed to github-pages September 20, 2022 17:14 Inactive
@colebemis colebemis merged commit c76e161 into main Sep 20, 2022
@colebemis colebemis deleted the treeview-current branch September 20, 2022 17:14
@primer-css primer-css mentioned this pull request Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants