Add min-delay to phx-disable-with text content change

I really like the behavior of the phx-disable-with attribute for providing feedback to the user when something happens, but i find that for users on a fast connection, it can be a little jarring to have the button text change so rapidly. This is especially the case when editing something in place and the form doesn’t do a redirect.

Would there be interest in adding a phx-disable-with-delay type attribute, which would only change the text content after X number of milliseconds?

I’d be happy to attempt a PR, but I didn’t want to go through the work if there was no interest.

Thanks!

2 Likes

Not a liveview expert, but that sounds like what phx-debounce and phx-throttle can do?

https://hexdocs.pm/phoenix_live_view/bindings.html#rate-limiting-events-with-debounce-and-throttle

Those attributes are a little bit different - as those add delay to the time that the change events are triggered and sent over the socket.

My proposed attribute would purely be cosmetic - it wouldn’t change the timing of when the event is sent over the socket, it would only add a delay to when the textContent of the button changes.

My suggestion is similar to the change to the topbar to add a minimum delay before it displays.

Unless there is a recent change I’m unaware of it would be nice to allow the disconnected message to have a brief delay as well.

1 Like