Skip to content

Add align prop on ActionMenu.Overlay to pass through to AnchoredOverlay #1921

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/actionmenu-add-align-prop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/react': minor
---

Add align prop on ActionMenu.Overlay to pass through to AnchoredOverlay
9 changes: 5 additions & 4 deletions docs/content/ActionMenu.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,11 @@ render(

### ActionMenu.Overlay

| Name | Type | Default | Description |
| :--------------------------------------- | :-------------------- | :-----------------: | :-------------------------------------------------------------------------------------------- |
| children\* | `React.ReactElement[] | React.ReactElement` | Required. Recommended: [`ActionList`](/ActionList) |
| [OverlayProps](/Overlay#component-props) | - | - | Optional. Props to be spread on the internal [`AnchoredOverlay`](/AnchoredOverlay) component. |
| Name | Type | Default | Description |
| :--------------------------------------- | :------------------------------------------------- | :-----: | :-------------------------------------------------------------------------------------- |
| children\* | `React.ReactElement` | `React.ReactElement[]` | - | Required. Recommended: [`ActionList`](/ActionList) |
| align | 'start' | 'center' | 'end' | 'start' | Optional. Passed down to internal [`AnchoredOverlay`](/AnchoredOverlay#props) component |
| [OverlayProps](/Overlay#component-props) | - | - | Optional. Props to be spread on the internal [`Overlay`](/Overlay) component. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use the PropsTable component here?

Copy link
Member Author

@siddharthkp siddharthkp Mar 7, 2022

Choose a reason for hiding this comment

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

Will create another PR with ActionList in it too! (Don't want to miss the v35 train) - #1931


## Status

Expand Down
6 changes: 5 additions & 1 deletion docs/content/AnchoredOverlay.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ See also [Overlay positioning](/Overlay#positioning).
const closeOverlay = React.useCallback(() => setIsOpen(false), [setIsOpen])
return (
<AnchoredOverlay
renderAnchor={anchorProps => <DropdownButton {...anchorProps}>Click me to open</DropdownButton>}
renderAnchor={anchorProps => (
<Button {...anchorProps} trailingIcon={TriangleDownIcon}>
Click me to open
</Button>
)}
open={isOpen}
onOpen={openOverlay}
onClose={closeOverlay}
Expand Down
4 changes: 3 additions & 1 deletion docs/src/@primer/gatsby-theme-doctocat/live-code-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
TypographyIcon,
VersionsIcon,
XIcon,
ZapIcon
ZapIcon,
TriangleDownIcon
} from '@primer/octicons-react'
import * as primerComponents from '@primer/react'
import * as drafts from '@primer/react/drafts'
Expand Down Expand Up @@ -85,6 +86,7 @@ export default function resolveScope(metastring) {
IterationsIcon,
NumberIcon,
SingleSelectIcon,
TriangleDownIcon,
Dialog2,
ConfirmationDialog,
useConfirm,
Expand Down
16 changes: 9 additions & 7 deletions src/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,14 @@ const MenuButton = React.forwardRef<AnchoredOverlayProps['anchorRef'], ButtonPro
)
})

type MenuOverlayProps = Partial<OverlayProps> & {
/**
* Recommended: `ActionList`
*/
children: React.ReactElement[] | React.ReactElement
}
const Overlay: React.FC<MenuOverlayProps> = ({children, ...overlayProps}) => {
type MenuOverlayProps = Partial<OverlayProps> &
Pick<AnchoredOverlayProps, 'align'> & {
/**
* Recommended: `ActionList`
*/
children: React.ReactElement[] | React.ReactElement
}
const Overlay: React.FC<MenuOverlayProps> = ({children, align = 'start', ...overlayProps}) => {
// we typecast anchorRef as required instead of optional
// because we know that we're setting it in context in Menu
const {anchorRef, renderAnchor, anchorId, open, onOpen, onClose} = React.useContext(MenuContext) as MandateProps<
Expand All @@ -107,6 +108,7 @@ const Overlay: React.FC<MenuOverlayProps> = ({children, ...overlayProps}) => {
open={open}
onOpen={openWithFocus}
onClose={onClose}
align={align}
overlayProps={overlayProps}
focusZoneSettings={{focusOutBehavior: 'wrap'}}
>
Expand Down
51 changes: 27 additions & 24 deletions src/stories/ActionMenu/fixtures.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -604,30 +604,33 @@ export function OverlayProps(): JSX.Element {
Disable `onClickOutside` and `onEscape`. Only way to close is to select an action which takes focus on a
TextInput
</p>
<ActionMenu open={open} onOpenChange={setOpen}>
<ActionMenu.Button>Menu</ActionMenu.Button>
<ActionMenu.Overlay
width="large"
onClickOutside={() => {
/* do nothing, keep it open*/
}}
onEscape={() => {
/* do nothing, keep it open*/
}}
returnFocusRef={inputRef}
>
<ActionList>
<ActionList.Item>Option 1</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
<Box sx={{display: 'flex', justifyContent: 'center'}}>
<ActionMenu open={open} onOpenChange={setOpen}>
<ActionMenu.Button>Menu</ActionMenu.Button>
<ActionMenu.Overlay
width="large"
align="center"
onClickOutside={() => {
/* do nothing, keep it open*/
}}
onEscape={() => {
/* do nothing, keep it open*/
}}
returnFocusRef={inputRef}
>
<ActionList>
<ActionList.Item>Option 1</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
<ActionList.Item>Option 2</ActionList.Item>
</ActionList>
</ActionMenu.Overlay>
</ActionMenu>
</Box>
<br />
<br />
<TextInput type="text" ref={inputRef} placeholder="Random input to return focus to" sx={{width: 280}} />
Expand Down