phoenix_live_view icon indicating copy to clipboard operation
phoenix_live_view copied to clipboard

put_flash doesn't close unless I press close button.

Open aliaihub opened this issue 2 years ago • 2 comments

Environment

  • Elixir version (elixir -v): ~> 1.14
  • Phoenix version (mix deps):~> 1.7.2
  • Phoenix LiveView version (mix deps): ~> 0.19.2
  • Operating system: Windows 11
  • Browsers you attempted to reproduce this bug on (the more the merrier): Chrome and Edge

Actual behavior

Currently the put_flash method only accepts three parameters put_flash(socket, :info, "It worked!") So we can't make to close automatically after sometimes and we need to click the close button.

Expected behavior

It is better to have an option for making it to close after some times.

aliaihub avatar Jul 16 '24 21:07 aliaihub

Hi @Erfan1995,

closing a flash is out of scope for LV itself, because it can be implemented quite easily in your application. LV supports the special lv:clear-flash event and you can use this together with a minimal client-side hook to automatically close the flash. For an example, see the LiveBeats application:

https://github.com/fly-apps/live_beats/blob/ac9780472e7019af274110a1cf71250a8d40c986/lib/live_beats_web/components/core_components.ex#L83

https://github.com/fly-apps/live_beats/blob/ac9780472e7019af274110a1cf71250a8d40c986/assets/js/app.js#L29-L40

SteffenDE avatar Jul 17 '24 08:07 SteffenDE

@SteffenDE Thank you so much for clarifications.

aliaihub avatar Jul 17 '24 15:07 aliaihub