Skip to content

chore(ActionMenu): Add fullscreen sample story #6108

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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/pink-trees-work.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

chore(ActionMenu): Add fullscreen sample story and variant prop
29 changes: 29 additions & 0 deletions packages/react/src/ActionMenu/ActionMenu.examples.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,35 @@ export const CustomOverlayProps = () => {
)
}

export const FullScreen = () => {
const [open, setOpen] = React.useState(false)

return (
<Box sx={{display: 'flex', justifyContent: 'center'}}>
<ActionMenu open={open} onOpenChange={setOpen}>
<ActionMenu.Button>Menu</ActionMenu.Button>
<ActionMenu.Overlay
width="large"
align="center"
preventOverflow={false}
variant={{regular: 'anchored', narrow: 'fullscreen'}}
>
<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>
)
}

export const ControlledMenu = () => {
const [actionFired, fireAction] = React.useState('')
const onSelect = (name: string) => fireAction(name)
Expand Down
4 changes: 3 additions & 1 deletion packages/react/src/ActionMenu/ActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ const MenuButton = React.forwardRef(({...props}, anchorRef) => {
}) as PolymorphicForwardRefComponent<'button', ActionMenuButtonProps>

Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

The newly added variant prop should be documented (e.g., in JSDoc or PropTypes) to clarify the allowed shapes and describe its behavior for maintainers and consumers.

Suggested change
/**
* Props for the `Overlay` component used in the `ActionMenu`.
*
* @property variant - Determines the style of the overlay. It is an object with two optional keys:
* - `regular`: Specifies the variant for regular screens. Default is `'anchored'`.
* - `narrow`: Specifies the variant for narrow screens. Default is `'anchored'`.
* Example: `{regular: 'anchored', narrow: 'floating'}`.
*/

Copilot uses AI. Check for mistakes.

type MenuOverlayProps = Partial<OverlayProps> &
Pick<AnchoredOverlayProps, 'align' | 'side'> & {
Pick<AnchoredOverlayProps, 'align' | 'side' | 'variant'> & {
/**
* Recommended: `ActionList`
*/
Expand All @@ -242,6 +242,7 @@ const Overlay: React.FC<React.PropsWithChildren<MenuOverlayProps>> = ({
side,
onPositionChange,
'aria-labelledby': ariaLabelledby,
variant = {regular: 'anchored', narrow: 'anchored'},
Copy link
Preview

Copilot AI May 22, 2025

Choose a reason for hiding this comment

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

Defining the default variant object inline recreates a new reference on every render, which can cause unnecessary re-renders of AnchoredOverlay. Consider moving the default into a const outside the component to keep the reference stable.

Copilot uses AI. Check for mistakes.

...overlayProps
}) => {
// we typecast anchorRef as required instead of optional
Expand Down Expand Up @@ -285,6 +286,7 @@ const Overlay: React.FC<React.PropsWithChildren<MenuOverlayProps>> = ({
overlayProps={overlayProps}
focusZoneSettings={{focusOutBehavior: 'wrap'}}
onPositionChange={onPositionChange}
variant={variant}
>
<div ref={containerRef}>
<ActionListContainerContext.Provider
Expand Down
Loading