Problem: With the current implementation, the close_modal event gets sent twice to the LiveView if you push_patch from the close_modalhandle_event in the LiveView. First when phx-click calls hide_modal/2 and then again when phx-remove is executed after the push_patch removes the modal from the DOM.
Solution: Calls JS.push/2 before executing the function in phx-remove and removes the JS.push/2 from the phx-remove function. This update fixes the bug where close_modal event fires twice with server push_patch.
Also, adds on_cancel attr with default to existing JS.push/2 functionality so library users have the options of passing JS.patch/1 to avoid the round trip through the handle_event or %JS{} if they want to simply close the modal and remain on the current page without sending the close_modal event.
This PR borrows patterns from the latest modal component generated in a new Phoenix project, see here.
Problem: With the current implementation, the
close_modal
event gets sent twice to the LiveView if youpush_patch
from theclose_modal
handle_event
in the LiveView. First whenphx-click
callshide_modal/2
and then again whenphx-remove
is executed after thepush_patch
removes the modal from the DOM.Solution: Calls JS.push/2 before executing the function in
phx-remove
and removes theJS.push/2
from thephx-remove
function. This update fixes the bug whereclose_modal
event fires twice with serverpush_patch
.Also, adds
on_cancel
attr with default to existingJS.push/2
functionality so library users have the options of passing JS.patch/1 to avoid the round trip through thehandle_event
or%JS{}
if they want to simply close the modal and remain on the current page without sending theclose_modal
event.This PR borrows patterns from the latest
modal
component generated in a new Phoenix project, see here.