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

Menu component is not opening when it is controlled #2690

Closed
denizguzel opened this issue Oct 12, 2022 · 1 comment
Closed

Menu component is not opening when it is controlled #2690

denizguzel opened this issue Oct 12, 2022 · 1 comment

Comments

@denizguzel
Copy link
Contributor

What package has an issue

@mantine/core

Describe the bug

I believe this bug introduced with this pull request but I'm not sure exactly. #2646

In default state Menu is working fine but when I make it controlled like this example https://mantine.dev/core/menu/#controlled, Menu component doesn't open anymore.

Minimal reproduction link is attached.

What version of @mantine/hooks page do you have in package.json?

5.5.5

If possible, please include a link to a codesandbox with the reproduced problem

https://codesandbox.io/s/pedantic-chatterjee-zf560c

Do you know how to fix the issue

No

Are you willing to participate in fixing this issue and create a pull request with the fix

No

Possible fix

No response

@denizguzel
Copy link
Contributor Author

Instead of doing this

const [opened, setOpened] = useState(false);

<Menu opened={opened} onChange={setOpened}>
  <Menu.Target>
    <Button>Toggle menu</Button>
  </Menu.Target>

  <Menu.Dropdown>
    <Menu.Label>Application</Menu.Label>
    <Menu.Divider />
    <Menu.Label>Danger zone</Menu.Label>
  </Menu.Dropdown>
</Menu>

I refactored the code like this and it works now.

const [opened, setOpened] = useState(false);

const handleMenuToggle = () => {
  setOpened((prev) => !prev);
};

<Menu opened={opened}>
  <Menu.Target>
    <Button onClick={handleMenuToggle}>Toggle menu</Button>
  </Menu.Target>

  <Menu.Dropdown>
    <Menu.Label>Application</Menu.Label>
    <Menu.Divider />
    <Menu.Label>Danger zone</Menu.Label>
  </Menu.Dropdown>
</Menu>

I don't know if it was a bug or not, but closing the issue for now. Thanks

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