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

Add truncation features to the LabelGroup component #3264

Merged
merged 46 commits into from
Jul 28, 2023

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented May 8, 2023

These changes add the following truncation features to the LabelGroup component:

  • truncate LabelGroup children after a static number of children (for example, truncate after the 5th label)
  • truncate LabelGroup children to fit in the width of the parent

Consumers can choose to show the full list of labels inline or in an Overlay.

Closes https://github.com/github/primer/issues/2006

Screenshots

Truncate after n children and show the full list inline

Note: this screen recording is slightly out of date. Instead of rendering a "—" icon to collapse tokens, we now show a text button that says "Show less"

Kapture.2023-05-08.at.16.57.18.mp4

Truncate to fit parent width and show the full list in an overlay

Kapture.2023-05-08.at.16.58.59.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.

@mperrotti mperrotti requested review from a team and langermank May 8, 2023 21:00
@changeset-bot
Copy link

changeset-bot bot commented May 8, 2023

🦋 Changeset detected

Latest commit: 674274b

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 May 8, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 103.65 KB (+1.24% 🔺)
dist/browser.umd.js 104.21 KB (+1.2% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-3264 May 8, 2023 21:07 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 May 8, 2023 21:10 Inactive
@primer primer bot temporarily deployed to github-pages May 8, 2023 21:11 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 May 8, 2023 21:11 Inactive
src/__tests__/LabelGroup.test.tsx Outdated Show resolved Hide resolved
// We need to manually re-focus the collapse button if we're not showing the full
// list in an overlay.
// TODO: get rid of this hack
setTimeout(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Help wanted: I used this setTimeout because we need to wait until state has been updated and the expand button is back in the DOM.

This feels sloppy/hacky, but I haven't been able to figure out a better way. @siddharthkp - we paired on this last week.

src/__tests__/LabelGroup.test.tsx Outdated Show resolved Hide resolved
@mperrotti mperrotti temporarily deployed to github-pages May 8, 2023 21:18 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 May 8, 2023 21:19 Inactive
@mperrotti mperrotti requested a review from broccolinisoup May 8, 2023 21:26
src/LabelGroup/LabelGroup.tsx Show resolved Hide resolved
src/AnchoredOverlay/AnchoredOverlay.tsx Show resolved Hide resolved
src/__tests__/LabelGroup.test.tsx Outdated Show resolved Hide resolved
@colebemis colebemis self-requested a review May 9, 2023 21:29
@mperrotti mperrotti temporarily deployed to github-pages May 9, 2023 21:41 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 May 9, 2023 21:42 Inactive
@mperrotti mperrotti temporarily deployed to github-pages May 9, 2023 22:18 — with GitHub Actions Inactive
@mperrotti mperrotti temporarily deployed to github-pages July 21, 2023 14:56 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 July 21, 2023 14:57 Inactive
@mperrotti mperrotti temporarily deployed to github-pages July 21, 2023 17:39 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 July 21, 2023 17:39 Inactive
@mperrotti mperrotti temporarily deployed to github-pages July 25, 2023 17:33 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 July 25, 2023 17:33 Inactive
@mperrotti
Copy link
Contributor Author

@broccolinisoup - could you give this another look when you get a chance?

@mperrotti mperrotti temporarily deployed to github-pages July 26, 2023 23:21 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3264 July 26, 2023 23:22 Inactive
Copy link
Member

@broccolinisoup broccolinisoup left a comment

Choose a reason for hiding this comment

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

Thanks so much @mperrotti

I tested it again with the issues I mentioned before in mind and all working beautifully ✨

Tested with a mouse and keyboard

  • Non interactive tokens with auto truncate/expand inline
  • Non interactive tokens with auto truncate/expand overlay
  • Interactive tokens with auto truncate/expand inline
  • Interactive tokens with auto truncate/expand overlay

On Chrome, Safari, Edge and Firefox.

It looks great to me overall. Just tiny styling and focus issue I just discovered but I don't think it is a blocker for this PR. Let me know what you think.

Focus ring on Edge (latest)

Label Group interactive tokens story open on edge browser and the third token is focused and the focus ring is black

Initial focus is wrong on Firefox

Initial focus on Firefox jumps to the element that is just before the +X in this story (components-labelgroup-features--truncate-auto-expand-inline-with-interactive-tokens) I can't add a video sorry - something is wrong with my Kap but let me know if you can't replicate it.

Otherwise, I love these changes and thanks for your patience with my while I was being nitpicky 😁

@mperrotti
Copy link
Contributor Author

@broccolinisoup - I'm able to reproduce the focus order problem in Firefox. I have no idea why this is happening, but I think we need to fix it before we can merge this :(

Kapture.2023-07-27.at.09.45.47.mp4

@ericwbailey
Copy link
Contributor

ericwbailey commented Jul 27, 2023

I am unable to reproduce this on https://primer-018a39f5ea-13348165.drafts.github.io/storybook/?path=/story/components-labelgroup-features--truncate-auto-with-interactive-tokens.

Firefox 115.0.2 on macOS Ventura 13.5 in a private window.

One thing I'm wondering: is focus following last click placement? That can affect things.

results.mov

@mperrotti
Copy link
Contributor Author

Interesting - I'm also on Firefox 115.0.2, but macOS Ventura 13.4.1.

I'm going to play with it a little bit more, but I think it might be safe to merge as-is.

@mperrotti
Copy link
Contributor Author

I'm not able to reproduce when I load the story in it's own window. I think it's safe to merge 🙂

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.

4 participants