Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TreeView: Add support for leading and trailing visuals #2383

Merged
merged 15 commits into from
Sep 30, 2022
Merged

Conversation

colebemis
Copy link
Contributor

@colebemis colebemis commented Sep 28, 2022

Summary

Adds TreeView.LeadingVisual, TreeView.TrailingVisual, and TreeView.DirectoryIcon components to support leading and trailing visuals:

👉 Try it out

Before After
CleanShot 2022-09-28 at 15 28 20@2x CleanShot 2022-09-28 at 15 27 40@2x

Open questions

  • How should leading and trialing visuals impact the aria-label of a tree item?
  • Should we add a design token to Primer Primitives for the "directory icon" color?

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.

@changeset-bot
Copy link

changeset-bot bot commented Sep 28, 2022

🦋 Changeset detected

Latest commit: 4787ccb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Sep 28, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 77.1 KB (0%)
dist/browser.umd.js 77.71 KB (0%)

@colebemis colebemis temporarily deployed to github-pages September 28, 2022 21:35 Inactive
@colebemis colebemis changed the title Treeview: Add support for leading and trailing visuals TreeView: Add support for leading and trailing visuals Sep 28, 2022
@colebemis colebemis temporarily deployed to github-pages September 28, 2022 21:47 Inactive
@colebemis colebemis temporarily deployed to github-pages September 28, 2022 21:56 Inactive
@colebemis colebemis temporarily deployed to github-pages September 28, 2022 22:24 Inactive
@colebemis colebemis marked this pull request as ready for review September 28, 2022 22:30
@colebemis colebemis temporarily deployed to github-pages September 29, 2022 16:03 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.

Looks good. Only comments are about examples and stories - not the actual implementation.

</TreeView.LeadingVisual>
Avatar.tsx
<TreeView.TrailingVisual>
<StyledOcticon icon={DiffAddedIcon} color="success.fg" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these trailing visuals are used to visually communicate diff status, I'm pretty sure they should have an aria-label.

cc @ericwbailey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. How should the aria-label for the trailing visual impact the aria-label of the treeitem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, the aria-label would be Avatar.tsx added. That seems correct but I'd love confirmation from @ericwbailey.

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 updated the docs and stories to include aria-label on these trailing visuals 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to get to this after merging. I try to avoid using aria-label on non-interactive elements, given their mixed support. In the API guidance I am recommending content that uses both aria-hidden="true" and a sr-only class applied to it.

In addition to the mixed support concern, we're also going to be using the text string to construct aria-labeledby announcements for the relevant TreeView node.

{childrenWithoutSubTree}
<Slots>
{slots => (
// QUESTION: How should leading and trailing visuals impact the aria-label?
Copy link
Contributor

Choose a reason for hiding this comment

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

Which aria-label are you talking about?

I don't think we'll need content that is accessible to assistive tech for most trailing and leading visuals.

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'm thinking about the aria-label for the element with role=treeitem.

const DirectoryIcon = () => {
const {isExpanded} = React.useContext(ItemContext)
const icon = isExpanded ? FileDirectoryOpenFillIcon : FileDirectoryFillIcon
// TODO: Use correct color
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll open a @primer/primitives PR with the folder color.

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -10,63 +10,98 @@ description: A hierarchical list of items where nested items can be expanded and
### File tree navigation without directory links
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we get an example (and maybe a story?) showing how to use the isExpanded render prop to set different icons for expanded and collapsed states.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great idea 👍 Let me know if the docs I added make sense

@colebemis colebemis temporarily deployed to github-pages September 30, 2022 00:46 Inactive
docs/content/TreeView.mdx Outdated Show resolved Hide resolved
docs/content/TreeView.mdx Outdated Show resolved Hide resolved
docs/content/TreeView.mdx Outdated Show resolved Hide resolved
@colebemis colebemis temporarily deployed to github-pages September 30, 2022 17:00 Inactive
@colebemis colebemis merged commit 81013a7 into main Sep 30, 2022
@colebemis colebemis deleted the treeview-visuals branch September 30, 2022 17:02
@primer-css primer-css mentioned this pull request Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants