Ah, you’re toggling visibility within livewire. Just a head’s up, doing it this way will be a little more laggy once on a server outside of your local network. This is because you’re transmitting the close action through ajax and then it has to round trip back to execute it on the front end.
In this case, you wouldn’t need the x-data as it’s handled directly in livewire. But if you run into a sluggish interface after development, handle the modal closing in javascript. You can cascade the window.livewire.emit
to handle whatever backend stuff you need to handle for cleaning up the closed modal.
If you want to keep it within your component, you can use a blade stack for your javascript:
// modal.blade.php
@push('stack')
<script>
document.onkeydown = function(e) {
if (e.keyCode == 27) {
window.livewire.emit('closeModals')
}
};
</script>
@endpush