trimmings icon indicating copy to clipboard operation
trimmings copied to clipboard

"Before Cache" / "Event" feature

Open snellingio opened this issue 6 years ago • 2 comments

I'd like to create a dropdown with the Toggle feature. However, the toggle will remain open on hitting the back button with Turbolinks. Using stimulus and turbolinks, I'd normally either remove the node or add / remove a class.

Maybe there is room for a before cache feature? Or alternatively, maybe an event feature might keep it more flexible?

snellingio avatar Sep 03 '19 02:09 snellingio

The more I think about it, maybe we should have an event option on most of the features.

That way, I can write a javascript "plugin" more or less that will fire the events to control the page.

My usecase is hooking up certain events with laravel's echo websocket server. I'd like to refresh an element or something similar by firing an event.

Definitely needed with the replace function, but I'll keep searching the codebase to see if there is anything else using a similar architecture.

snellingio avatar Sep 03 '19 02:09 snellingio

Can you solve this problem by using <details> instead of toggle? Alternatively, you could write some Javascript that listens for turbolinks:load and toggles your element by sending a click event. I do something very similar to this on the Trimmings docs, in fact; check out adjustNav in the source.

Trimmings strives to augment existing DOM APIs, so in essence it already does have an event option. Since most Trimmings feature are listening for clicks and submits, you can send a click or submit event to a Trimmings-bound element yourself based on whatever logic you may need for your particular use case.

I think this answers your question, but let me know if I've missed the point here. Thanks!

johnholdun avatar Nov 22 '19 18:11 johnholdun