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: Support async behavior #2388

Merged
merged 10 commits into from
Oct 3, 2022
Merged

TreeView: Support async behavior #2388

merged 10 commits into from
Oct 3, 2022

Conversation

colebemis
Copy link
Contributor

@colebemis colebemis commented Sep 30, 2022

Summary

  • Adds storybook stories demonstrating how to asynchronously load TreeView items (with success and error states).
  • Adds a TreeView.LoadingItem component to render while loading TreeView items.

Demos

Loading items (success)

👉 Try it out

CleanShot.2022-09-30.at.11.22.07.mp4

Loading items (error)

👉 Try it out

CleanShot.2022-09-30.at.10.49.04.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.

@changeset-bot
Copy link

changeset-bot bot commented Sep 30, 2022

🦋 Changeset detected

Latest commit: 172987e

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

size-limit report 📦

Path Size
dist/browser.esm.js 77.18 KB (0%)
dist/browser.umd.js 77.81 KB (0%)

@colebemis colebemis temporarily deployed to github-pages September 30, 2022 18:00 Inactive
onExpandedChange={async isExpanded => {
if (asyncItems.length === 0 && isExpanded) {
// Show loading indicator after a short delay
const timeout = setTimeout(() => setIsLoading(true), 500)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙋 Is showing the loading item after a short delay an accessible pattern? cc @ericwbailey

Copy link
Contributor

Choose a reason for hiding this comment

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

Context for @ericwbailey: we do this to avoid showing loading indicators before a user might need them. When users see a lot of loading indicators, I think it makes the UI seem slower than it actually is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be okay.

const LoadingItem: React.FC = () => {
return (
// TODO: What aria attributes do we need to add here?
<Item>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙋 What aria props should we add to the LoadingItem? cc @ericwbailey

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm in the process of testing this out, but I believe we'll need a combination of aria-hidden (to hide decorative nodes), aria-busy (to communicate loading state), and aria-live (to announce state change).

<TreeView.SubTree>
{isLoading ? <TreeView.LoadingItem /> : null}
{error ? (
<ConfirmationDialog
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙋 Is ConfirmationDialog the right kind of dialog for error messages? cc @ericwbailey

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so

Copy link
Contributor

Choose a reason for hiding this comment

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

I think so as well.

@colebemis colebemis marked this pull request as ready for review September 30, 2022 18:31
@colebemis colebemis requested review from a team and siddharthkp September 30, 2022 18:31
@colebemis colebemis temporarily deployed to github-pages September 30, 2022 18:34 Inactive
@colebemis colebemis requested review from ericwbailey and mperrotti and removed request for siddharthkp September 30, 2022 18:48
@colebemis colebemis temporarily deployed to github-pages September 30, 2022 19:25 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.

Approved because we discussed doing the ARIA work in a follow-up PR

)
}

LoadingItem.displayName = 'TreeView.LoadingItem'
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this. I'm going to start doing this instead of keeping the name of the const.

onExpandedChange={async isExpanded => {
if (asyncItems.length === 0 && isExpanded) {
// Show loading indicator after a short delay
const timeout = setTimeout(() => setIsLoading(true), 500)
Copy link
Contributor

Choose a reason for hiding this comment

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

500ms felt a little too long to see expanded content. Maybe we could try 250-300ms?

This is non-blocking feedback and just one person's opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I'll reduce it to 300ms

@@ -417,7 +434,7 @@ const LeadingVisual: React.FC<TreeViewVisualProps> = props => {
const children = typeof props.children === 'function' ? props.children({isExpanded}) : props.children
return (
<Slot name="LeadingVisual">
<Box sx={{color: 'fg.muted'}}>{children}</Box>
<Box sx={{display: 'flex', color: 'fg.muted'}}>{children}</Box>
Copy link
Contributor

Choose a reason for hiding this comment

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

What do we need flexbox for? Is it just a vertical alignment thing? Or are we actually laying out multiple children?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When you render an SVG (Octicon) in the leading visual slot, it adds unwanted extra space unless the container is a flex container.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I figured it was something like that. I've dealt with that before, and I don't understand why it works 🙈

I think it also works for grid

docs/content/TreeView.mdx Outdated Show resolved Hide resolved
@colebemis colebemis temporarily deployed to github-pages October 3, 2022 20:25 Inactive
@colebemis colebemis merged commit d459364 into main Oct 3, 2022
@colebemis colebemis deleted the treeview-async branch October 3, 2022 20:26
@primer-css primer-css mentioned this pull request Oct 3, 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