I assume you mean JS.toggle_attribute? JS.toggle is not new and simply toggles visibility by setting style="display: none" and style="display: block" (whatever visible display type you tell it to).
Haha well, I was just trying to break it down to the simplest thing possible for debugging purposes. The actual code is a proper dropdown menu but it’s my habit to just get something working and then build on that.
Your example doesn’t work for me, it also does nothing. The aria-expanded property of #menu doesn’t change. Does it work for you?
OK, the plot thickens. I phx.new’d a brand new app with 1.7.11, copied it in and it works there. Evidentally my upgrade of liveview et al is not as functional as I thought it was.
I’ve copied over /priv/static/app.js etc and will mess around to see what’s going on. Maybe a good time to learn how these files are actually being included in the first place, a deps update evidentally wasn’t enough to do the trick…
OK. I tracked it down to some legacy live-views.js hooks file which was somehow breaking only that. I’ve now terminated it with extreme prejudice. So strange that it didn’t also break other things, like JS.toggle() - if everything else hadn’t worked I would have suspected something in the assets from the beginning. But no, it only broke that. Bizarre.
Anyway - thank you for all the help and confirming that what i was doing actually should have worked all along. Next time, I’ll check in a new, clean project first…
And now, if you’ll excuse me, I’m off to have a little “chat” with the person who wrote that hook file…