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: Implement markup #2305

Merged
merged 16 commits into from
Sep 13, 2022
Merged

TreeView: Implement markup #2305

merged 16 commits into from
Sep 13, 2022

Conversation

colebemis
Copy link
Contributor

@colebemis colebemis commented Sep 2, 2022

This PR implements the bare bones of the TreeView component. My focus for this PR is to get TreeView rendering accessible markup (as defined by the TreeView spec).

Acceptance criteria

We can merge this PR when we're happy with the markup rendered in these TreeView storybook stories:

Screenshots

CleanShot 2022-09-08 at 15 46 54@2x

Merge checklist

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

Next steps

  • Implement arrow key navigation

@changeset-bot
Copy link

changeset-bot bot commented Sep 2, 2022

🦋 Changeset detected

Latest commit: 3f3ab76

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 2, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 76.3 KB (0%)
dist/browser.umd.js 76.94 KB (0%)

@colebemis colebemis temporarily deployed to github-pages September 2, 2022 21:36 Inactive
@colebemis colebemis temporarily deployed to github-pages September 8, 2022 22:43 Inactive
@colebemis colebemis marked this pull request as ready for review September 8, 2022 22:51
@colebemis colebemis requested review from a team, rezrah, ericwbailey, joshblack and mperrotti and removed request for rezrah September 8, 2022 22:51
@colebemis colebemis added the react label Sep 8, 2022
@colebemis colebemis temporarily deployed to github-pages September 8, 2022 23:01 Inactive
}

// TODO: Use an <a> element to enable native browser behavior like opening links in a new tab
const LinkItem: React.FC<TreeViewLinkItemProps> = ({href, onSelect, ...props}) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not using a <a> element here based on a recommendation from @jscholes. Later, let's investigate whether there's an accessible way to use an <a> element so we don't lose out on native browser link features (like opening links in a new tab).

Copy link
Member

Choose a reason for hiding this comment

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

Oh interesting! I wonder what the accessibility concerns with <a> are?

Copy link
Contributor

Choose a reason for hiding this comment

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

@broccolinisoup - it's not the <a> itself, it's the markup that would be required to make it work. It would be easier to explain in a Loom or on a Zoom call/screenshare if you want the details.

Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

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

Looks great! Sharing the checklist that I used below, the only thing that I noticed was the label for the group of items (which I think you have as a TODO). Also was curious if the intent was for aria-current was to be used or not in the navigation case.

Checklist

  • role="navigation", <nav>
    • Contains the role="tree" element if its treeitem elements are links
    • Has an accessible label describing the landmark content
  • role="tree" 1
    • Container uses role="tree"
    • Every descendant of role="tree" has role="treeitem"
  • role="treeitem"2
    • Contained in an element with role="tree" or role="group"
    • Expandable collection of treeitem elements are enclosed in an element with role="group"
    • role="treeitem" uses aria-expanded to communicate expansion
    • Click target for expansion should not be focusable
    • A group of expandable treeitem elements should be hidden or display: none when not expanded
    • A group of expandable treeitem elements is aria-labelledby by the label of the role="treeitem" element
    • A navigable treeitem element should communicate if its the current element within the group with aria-current="page"

Questions

  • Is there a good place to learn more about the aria-level requirement? It's something that I've always avoided if the markup can communicate the level

Footnotes

  1. https://w3c.github.io/aria/#tree

  2. https://w3c.github.io/aria/#treeitem

src/TreeView/TreeView.tsx Outdated Show resolved Hide resolved
docs/content/TreeView.mdx 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 9, 2022 19:03 Inactive
@colebemis
Copy link
Contributor Author

colebemis commented Sep 9, 2022

@joshblack Thanks for such a thorough review! ❤️

A group of expandable treeitem elements is aria-labelledby by the label of the role="treeitem" element

Yup, I left a TODO comment about this. I plan to address this when adding the LeadingVisual and TrailingVisual components because they'll impact how we generate the treeitem label.

A navigable treeitem element should communicate if its the current element within the group with aria-current="page"

I'm also planning to address this in a future PR. I'd like to implement the aria-current prop and associated styles in one PR.

Is there a good place to learn more about the aria-level requirement? It's something that I've always avoided if the markup can communicate the level

I was following the guidance in the TreeView API spec put together by @mperrotti and @ericwbailey: https://github.com/github/primer/pull/1273/files. They might know more about aria-level.

src/TreeView/TreeView.tsx Outdated Show resolved Hide resolved
@colebemis colebemis temporarily deployed to github-pages September 9, 2022 21:34 Inactive
docs/content/TreeView.mdx Outdated Show resolved Hide resolved
@colebemis colebemis temporarily deployed to github-pages September 9, 2022 21:51 Inactive
@colebemis colebemis temporarily deployed to github-pages September 9, 2022 22:15 Inactive
@colebemis colebemis temporarily deployed to github-pages September 13, 2022 21:29 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.

Markup looks correct based on our discussions with @jscholes and @ericwbailey 👍

I'm really hoping we can come back to this and figure out how to make <a> work so we don't lose native browser link features 🤞

}

// TODO: Use an <a> element to enable native browser behavior like opening links in a new tab
const LinkItem: React.FC<TreeViewLinkItemProps> = ({href, onSelect, ...props}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

@broccolinisoup - it's not the <a> itself, it's the markup that would be required to make it work. It would be easier to explain in a Loom or on a Zoom call/screenshare if you want the details.

@colebemis colebemis merged commit 6cd50a5 into main Sep 13, 2022
@colebemis colebemis deleted the treeview-markup branch September 13, 2022 21:31
@primer-css primer-css mentioned this pull request Sep 13, 2022
@colebemis colebemis changed the title Implement Treeview markup TreeView: Implement markup Sep 19, 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