Uh oh!
There was an error while loading. Please reload this page.
Action Menu - #1152
Conversation
…ce (indent) by non-selected items
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/primer/primer-components/6Pf5QKqrxDs9MszsjKXK38WbVK52 |
| --- | ||
| 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 |
There was a problem hiding this comment.
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} /> |
There was a problem hiding this comment.
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.
5f93566 to
4b5023fCompare| renderAnchor?: (props: any) => JSX.Element | ||
| triggerContent?: React.ReactNode | ||
| renderItem?: (props: ItemProps) => JSX.Element | ||
| onActivate?: (props: ItemProps) => void |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Out of curiosity: Does (an ActionMenu-level) onActivate prop support any use case that couldn’t be handled by (Item-level) onClick handlers?
There was a problem hiding this comment.
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' { | |||
There was a problem hiding this comment.
This makes for easier testing in node, rather than using window.crypto.getRandomValue
There was a problem hiding this comment.
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:
- 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)
- If
window.crypto.getRandomValueis onerous, how many lines of code would it take to produce a utility function which provides a nicer API but useswindow.crypto.getRandomValueinternally?
There was a problem hiding this comment.
It's such a simple method, I went ahead and just replaced it with a util that will generate a random string 👍
VanAnderson
commented
Apr 8, 2021
Not sure why vercel is failing - I don't have access to check the logs. |
| // ** | ||
| tabIndex?: number | ||
| ref?: React.RefObject<HTMLDivElement> |
There was a problem hiding this comment.
is there some sort of predefined type or interface we can use for these?
There was a problem hiding this comment.
Both tabIndex and ref would be available if the ListPropsBase interface extends’d React.ComponentPropsWithRef<'div'>
| <div>{text}</div> | ||
| {description && <DescriptionContainer>{description}</DescriptionContainer>} | ||
| </StyledTextContainer> | ||
| {AuxilaryIcon && ( |
There was a problem hiding this comment.
Nice work here! I love how this is consistent with the other conditional rendering (based on props) 🎊
| return ( | ||
| <StyledList {...props}> | ||
| <StyledList ref={containerRef as React.RefObject<HTMLDivElement>} {...props}> |
There was a problem hiding this comment.
I had trouble making typescript happy here without it - though this pattern seems to be used other places in the code for this specific use case of the focusZone/focusTrap hooks.
I think there is going to be some changes incoming to how focusZones/focusTraps are implemented into ActionMenu/DropdownMenu/ActionList - I will keep an eye on how that work settles out. This might be something good to pair on that we can fix in a few places if we can find a better pattern.
0df23c9 to
b1c11d7Compare… the Overlay open(rendered)/closed(not-rendered) state.
f289a2a to
d6095b9CompareUh oh!
There was an error while loading. Please reload this page.
| ]} | ||
| /> | ||
| ``` | ||
There was a problem hiding this comment.
Could you add an example that uses groupMetadata?
There was a problem hiding this comment.
done, just pulled from our ActionList docs on this one and kept them parallel.
colebemis
commented
Apr 16, 2021
Co-authored-by: Cole Bemis <colebemis@github.com>
VanAnderson
commented
Apr 16, 2021
colebemis
left a comment
There was a problem hiding this comment.
🚀 Nice work, @VanAnderson! ✨
dgreif
left a comment
There was a problem hiding this comment.
Looking great! Just a couple tweaks/questions 😄
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Dusty Greif <dgreif@users.noreply.github.com>
This reverts commit d6095b9.


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.
Fixes#1069