Skip to content

Commit

Permalink
Add support for controlling which side ActionMenu renders on (via a…
Browse files Browse the repository at this point in the history
… `side` prop on `ActionMenu.Overlay`) (#3714)

* Deduplicate `ActionMenu.tsx`

* Add `side` prop to `ActionMenu.Overlay`

* Add changeset

* Retrigger actions
  • Loading branch information
iansan5653 authored Sep 11, 2023
1 parent 3d7e72b commit 8834026
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changeset/brown-seahorses-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@primer/react': minor
---

Add support for controlling which side `ActionMenu` renders on (via a `side` prop on `ActionMenu.Overlay`)

<!-- Changed components: ActionMenu -->
8 changes: 7 additions & 1 deletion src/ActionMenu/ActionMenu.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@
"type": "start | center | end",
"defaultValue": "start",
"description": ""
},
{
"name": "side",
"type": "| 'inside-top' | 'inside-bottom' | 'inside-left' | 'inside-right' | 'inside-center' | 'outside-top' | 'outside-bottom' | 'outside-left' | 'outside-right'",
"defaultValue": "'outside-bottom'",
"description": "Controls which side of the anchor the menu will appear"
}
],
"passthrough": {
Expand All @@ -83,4 +89,4 @@
}
}
]
}
}
27 changes: 27 additions & 0 deletions src/ActionMenu/ActionMenu.examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,30 @@ export const DelayedMenuClose = () => {
</>
)
}

export const OnRightSide = () => (
<ActionMenu>
<ActionMenu.Button>Open menu</ActionMenu.Button>
<ActionMenu.Overlay width="medium" side="outside-right">
<ActionList>
<ActionList.Item onSelect={() => alert('Copy link clicked')}>
Copy link
<ActionList.TrailingVisual>⌘C</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Item onSelect={() => alert('Quote reply clicked')}>
Quote reply
<ActionList.TrailingVisual>⌘Q</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Item onSelect={() => alert('Edit comment clicked')}>
Edit comment
<ActionList.TrailingVisual>⌘E</ActionList.TrailingVisual>
</ActionList.Item>
<ActionList.Divider />
<ActionList.Item variant="danger" onSelect={() => alert('Delete file clicked')}>
Delete file
<ActionList.TrailingVisual>⌘D</ActionList.TrailingVisual>
</ActionList.Item>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
)
4 changes: 3 additions & 1 deletion src/ActionMenu/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const MenuButton = React.forwardRef(({...props}, anchorRef) => {
}) as PolymorphicForwardRefComponent<'button', ActionMenuButtonProps>

type MenuOverlayProps = Partial<OverlayProps> &
Pick<AnchoredOverlayProps, 'align'> & {
Pick<AnchoredOverlayProps, 'align' | 'side'> & {
/**
* Recommended: `ActionList`
*/
Expand All @@ -94,6 +94,7 @@ type MenuOverlayProps = Partial<OverlayProps> &
const Overlay: React.FC<React.PropsWithChildren<MenuOverlayProps>> = ({
children,
align = 'start',
side = 'outside-bottom',
'aria-labelledby': ariaLabelledby,
...overlayProps
}) => {
Expand All @@ -116,6 +117,7 @@ const Overlay: React.FC<React.PropsWithChildren<MenuOverlayProps>> = ({
onOpen={onOpen}
onClose={onClose}
align={align}
side={side}
overlayProps={overlayProps}
focusZoneSettings={{focusOutBehavior: 'wrap'}}
>
Expand Down

0 comments on commit 8834026

Please sign in to comment.