Skip to content

Action Menu #1152

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

Merged
merged 125 commits into from
Apr 16, 2021
Merged

Action Menu #1152

merged 125 commits into from
Apr 16, 2021

Conversation

VanAnderson
Copy link
Contributor

@VanAnderson VanAnderson commented Apr 2, 2021

Putting this into review although there are still a few outstanding items that need some attention - it should be ready to start getting eyes on it.

This component uses the ActionList as a base to create an accessible and customizable dropdown menu.

image

Fixes #1069

@changeset-bot
Copy link

changeset-bot bot commented Apr 2, 2021

⚠️ No Changeset found

Latest commit: 91da62d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@vercel
Copy link

vercel bot commented Apr 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/primer-components/6Pf5QKqrxDs9MszsjKXK38WbVK52
✅ Preview: https://primer-components-git-vananderson-action-menu-primer.vercel.app

Comment on lines 1 to 23
---
title: ActionMenu
---

An `ActionMenu` is a simple ActionList based component for define selectable menus.

## Default example

```jsx live
<ActionMenu
buttonContent="Menu"
items={[
{text: 'New file', onClick: () => console.log('Do Something!')},
ActionMenu.Divider,
{text: 'Copy link'},
{text: 'Edit file'},
{text: 'Delete file', variant: 'danger'}
]}
/>
```

## Component 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.

Going to fill this out just a bit more when the API settles out 👍

ComplexListStory.storyName = 'Complex List'

export function CustomTrigger(): JSX.Element {
const customAnchor = (props: any) => <Link {...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.

Making a note on this - ideally we should just be able to pass Link directly to renderAnchor, but that doesn't seem to work in the way I thought it would.

@smockle smockle mentioned this pull request Apr 5, 2021
7 tasks
renderAnchor?: (props: any) => JSX.Element
triggerContent?: React.ReactNode
renderItem?: (props: ItemProps) => JSX.Element
onActivate?: (props: ItemProps) => void
Copy link
Contributor Author

Choose a reason for hiding this comment

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

onActivate is passed in and will trigger when a menu item is clicked or selected with the keyboard keys. This will pass ItemProps into the callback so the action can use the selected item to respond to the click or keyboard event.

This onActivate method might be more useful to users if we allowed a meta key of item props, where users could store actionable information about an item that could be used by onActivate to perform the items task/route to the proper place.

Copy link
Member

@smockle smockle Apr 8, 2021

Choose a reason for hiding this comment

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

Out of curiosity: Does (an ActionMenu-level) onActivate prop support any use case that couldn’t be handled by (Item-level) onClick handlers?

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 think part of what this is trying to make a bit nicer is handling both click and keyboard functionality in one interface. I think to do the same thing with item level handlers would end up being a bit messy.

@@ -0,0 +1,4 @@
declare module 'get-random-values' {
Copy link
Contributor Author

@VanAnderson VanAnderson Apr 8, 2021

Choose a reason for hiding this comment

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

This makes for easier testing in node, rather than using window.crypto.getRandomValue

Copy link
Member

Choose a reason for hiding this comment

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

Historically, I believe we’ve avoided introducing external dependencies (especially ones without types) merely to improve the Primer developer experience (i.e. dependencies that do not also improve the experience of Primer consumers and the experience of their end-users).

Follow-up questions:

  1. Do we have established guidance about when to add third-party dependencies @colebemis @T-Hugs? (e.g. specific criteria dependencies must meet, specific situations when we’d avoid third-party solutions, guidelines for choosing between alternatives)
  2. If window.crypto.getRandomValue is onerous, how many lines of code would it take to produce a utility function which provides a nicer API but uses window.crypto.getRandomValue internally?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's such a simple method, I went ahead and just replaced it with a util that will generate a random string 👍

Base automatically changed from dropdownmenu to main April 16, 2021 19:37
@vercel vercel bot temporarily deployed to Preview April 16, 2021 19:53 Inactive
@VanAnderson VanAnderson force-pushed the VanAnderson/action-menu branch from f289a2a to d6095b9 Compare April 16, 2021 19:59
@vercel vercel bot temporarily deployed to Preview April 16, 2021 20:01 Inactive
@vercel vercel bot temporarily deployed to Preview April 16, 2021 20:06 Inactive
]}
/>
```

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add an example that uses groupMetadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, just pulled from our ActionList docs on this one and kept them parallel.

@colebemis
Copy link
Contributor

Is this difference in spacing between the right and the left intentional?

CleanShot 2021-04-16 at 13 20 52@2x

Co-authored-by: Cole Bemis <colebemis@github.com>
@vercel vercel bot temporarily deployed to Preview April 16, 2021 20:30 Inactive
@VanAnderson
Copy link
Contributor Author

Is this difference in spacing between the right and the left intentional?

Not intentional, just didn't notice it. I knocked out the right margin for the trailingVisualContainer, and I think this looks pretty even now:

image

@vercel vercel bot temporarily deployed to Preview April 16, 2021 20:50 Inactive
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

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

🚀 Nice work, @VanAnderson! ✨

@VanAnderson VanAnderson requested a review from dgreif April 16, 2021 21:17
Copy link
Member

@dgreif dgreif left a comment

Choose a reason for hiding this comment

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

Looking great! Just a couple tweaks/questions 😄

Co-authored-by: Dusty Greif <dgreif@users.noreply.github.com>
@vercel vercel bot temporarily deployed to Preview April 16, 2021 21:47 Inactive
@vercel vercel bot temporarily deployed to Preview April 16, 2021 21:58 Inactive
@vercel vercel bot temporarily deployed to Preview April 16, 2021 22:01 Inactive
@VanAnderson VanAnderson merged commit a975b5d into main Apr 16, 2021
@VanAnderson VanAnderson deleted the VanAnderson/action-menu branch April 16, 2021 22:06
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.

ActionMenu
5 participants