Skip to content

Commit

Permalink
feat: add onCloseAutoFocus to Menu.Content (#1845)
Browse files Browse the repository at this point in the history
  • Loading branch information
remidej authored Feb 3, 2025
1 parent a511ac5 commit ef9cd18
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-turtles-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': patch
---

feat: add onCloseAutoFocus to Menu.Content
13 changes: 7 additions & 6 deletions packages/design-system/src/components/SimpleMenu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,22 @@ const MenuTrigger = React.forwardRef<HTMLButtonElement, TriggerProps>(
* MenuContent
* -----------------------------------------------------------------------------------------------*/

interface ContentProps extends FlexProps<'div'> {
intersectionId?: string;
popoverPlacement?: `${NonNullable<DropdownMenu.DropdownMenuContentProps['side']>}-${NonNullable<DropdownMenu.DropdownMenuContentProps['align']>}`;
}
type ContentProps = FlexProps<'div'> &
Pick<DropdownMenu.DropdownMenuContentProps, 'onCloseAutoFocus'> & {
intersectionId?: string;
popoverPlacement?: `${NonNullable<DropdownMenu.DropdownMenuContentProps['side']>}-${NonNullable<DropdownMenu.DropdownMenuContentProps['align']>}`;
};

const MenuContent = React.forwardRef<HTMLDivElement, ContentProps>(
({ children, intersectionId, popoverPlacement = 'bottom-start', ...props }, ref) => {
({ children, intersectionId, onCloseAutoFocus, popoverPlacement = 'bottom-start', ...props }, ref) => {
const [side, align] = popoverPlacement.split('-') as [
DropdownMenu.DropdownMenuContentProps['side'],
DropdownMenu.DropdownMenuContentProps['align'],
];

return (
<DropdownMenu.Portal>
<DropdownMenuContent align={align} side={side} loop asChild>
<DropdownMenuContent align={align} side={side} loop onCloseAutoFocus={onCloseAutoFocus} asChild>
<Viewport
ref={ref}
direction="column"
Expand Down

0 comments on commit ef9cd18

Please sign in to comment.