Skip to content

Commit

Permalink
[POC] MenuButton - Option 2 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
michaldudak committed Jan 3, 2023
1 parent d17b252 commit 70f5b6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
24 changes: 13 additions & 11 deletions docs/pages/experiments/base/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,22 @@ export default function UnstyledMenuIntroduction() {
<Page>
<MenuButtonUnstyled
slots={{ root: MenuButton }}
label="My account"
open={isOpen}
onOpenChange={handleOpenChange}
popup={
<MenuUnstyled
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ root: { placement: 'bottom-start' }, listbox: { id: 'simple-menu' } }}
>
<StyledMenuItem onClick={createHandleMenuClick('Profile')}>Profile</StyledMenuItem>
<StyledMenuItem onClick={createHandleMenuClick('My account')}>
Language settings
</StyledMenuItem>
<StyledMenuItem onClick={createHandleMenuClick('Log out')}>Log out</StyledMenuItem>
</MenuUnstyled>
}
>
<MenuUnstyled
slots={{ root: Popper, listbox: StyledListbox }}
slotProps={{ root: { placement: 'bottom-start' }, listbox: { id: 'simple-menu' } }}
>
<StyledMenuItem onClick={createHandleMenuClick('Profile')}>Profile</StyledMenuItem>
<StyledMenuItem onClick={createHandleMenuClick('My account')}>
Language settings
</StyledMenuItem>
<StyledMenuItem onClick={createHandleMenuClick('Log out')}>Log out</StyledMenuItem>
</MenuUnstyled>
My account
</MenuButtonUnstyled>
</Page>
);
Expand Down
8 changes: 4 additions & 4 deletions packages/mui-base/src/MenuUnstyled/MenuButtonUnstyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import { useSlotProps } from '../utils';

export interface MenuButtonProps {
className?: string;
label?: string;
open?: boolean;
onOpenChange?: (
event: React.MouseEvent<HTMLButtonElement> | React.KeyboardEvent<HTMLButtonElement>,
open: boolean,
) => void;
defaultOpen?: boolean;
children?: React.ReactNode;
popup?: React.ReactNode;
slots?: {
root?: React.ElementType;
};
Expand All @@ -36,10 +36,10 @@ const MenuButton = React.forwardRef(function MenuButton(
) {
const {
children,
label,
open: openProp,
defaultOpen,
onOpenChange,
popup,
slots = {},
slotProps = {},
...other
Expand Down Expand Up @@ -102,8 +102,8 @@ const MenuButton = React.forwardRef(function MenuButton(

return (
<MenuTriggerContext.Provider value={contextValue}>
<Root {...rootProps}>{label}</Root>
{children}
<Root {...rootProps}>{children}</Root>
{popup}
</MenuTriggerContext.Provider>
);
});
Expand Down

0 comments on commit 70f5b6a

Please sign in to comment.