svelte-material-ui icon indicating copy to clipboard operation
svelte-material-ui copied to clipboard

MenuSurface.isOpen() is always false

Open yadomi opened this issue 2 years ago • 2 comments

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

  1. Use the demo from https://sveltematerialui.com/demo/menu-surface/
  2. 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

yadomi avatar Apr 15 '22 12:04 yadomi

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.

li6in9muyou avatar Apr 17 '22 06:04 li6in9muyou

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 ?

yadomi avatar Apr 29 '22 15:04 yadomi