svelte-material-ui
svelte-material-ui copied to clipboard
MenuSurface.isOpen() is always false
Describe the bug
When accessing isOpen()
from a menu surface, the function return false
while the menu is opened.
This prevent to create logic to close the meny when clicking a second time on the button that opened the menu in the first place.
To Reproduce
- Use the demo from https://sveltematerialui.com/demo/menu-surface/
- Log
isOpen()
in the button click
Expected behavior
isOpen()
should return true
when the menu is open
Additional context See console output in the REPL here when clicking on the button: https://svelte.dev/repl/043aa40c9afa43d692826872532f2ae9?version=3.47.0
In the REPL you provided, if you add the following line on line 13.
setInterval(()=>{console.log(surface?.isOpen())}, 500)
After you open the surface by clicking the button, while it's still open, you can see console logs true, until menu surface closes.
click button -> open menu surface -> click again -> menu surface lost focus -> menu surface is closed -> your on:click
callback -> logs false
If you pass managed=true
as props, you can toggle menu surface with consecutive button clicks as you expected in first your post. But now it won't close itself when it lost focus.
Indeed, didn't know about managed
props. I does makes sense then, but I feel having .isOpen
always to true in most case when managed=false
is a bit confusing.
Was this the desired behavior ?