Skip to content
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

Is there any way to observer the popupState? #123

Open
tamdc opened this issue Aug 15, 2023 · 1 comment
Open

Is there any way to observer the popupState? #123

tamdc opened this issue Aug 15, 2023 · 1 comment

Comments

@tamdc
Copy link

tamdc commented Aug 15, 2023

I need to catch the state change of submenu level 3 to change CSS property of lvl2. Each has their own popupState.

<MenuItemLv1 {...bindHover(lvl2MenuState)}>
    <Typography>Lv1 menu item</Typography>
    <Lvl2Menu
          transformOrigin={{ horizontal: 48, vertical: -48  }}
          {...bindMenu(lvl2MenuState)}
    >
         {lvl2menuItems.map(renderLv2MenuItem)}
    </Lvl2Menu>
</MenuItemLv1>

<MenuItemLv2 {...bindHover(lvl3MenuState)}>
    <Typography>Lv2 menu item</Typography>
    <Lvl3Menu
           anchorOrigin={{ horizontal: 'right', vertical: 'top' }}
           transformOrigin={{ horizontal: -24, vertical: 'top' }}
          {...bindMenu(lvl3MenuState)}
    >
         {lvl3menuItems.map(renderLv3MenuItem)}
    </Lvl3Menu>
</MenuItemLv2>

Do we have a prop callback that whenever the popupState change we can trigger the function passed through?

@jedwards1211
Copy link
Member

Sorry for the delay...there's no prop callback, but when level 3 opens or closes it will actually set the lvl2MenuState._childPopupState after a tick. So you could set CSS based upon lvl2MenuState._childPopupState?.open ? valueIfOpen : valueIfClosed.

(Note: _childPopupState starts with an underscore because I didn't exactly intend for people to rely on it, but I can't stop you 😄)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants