bastinald / laravel-livewire-modals

Dynamic Laravel Livewire Bootstrap modals.
66 stars 31 forks source link

Close on click out side. #9

Closed aliqasemzadeh closed 2 years ago

aliqasemzadeh commented 2 years ago

Hi I think we need close modal on click out side of modal. Untitled

heyjoe1984 commented 2 years ago

Publish the package view and remove data-bs-backdrop="static"

sbrow commented 1 year ago

For users who want only some modals to have a static backdrop, add the modal-static class to the modal-content element of your modal, then update your modals.js file accordingly. :)

// Bootstrap 4 users
  const modalsElement = document.getElementById('laravel-livewire-modals');
  const hasStaticModal = (el) => $(el).find('.modal-content.modal-static').length > 0;

  Livewire.on('showBootstrapModal', () => {
    $(modalsElement).attr('data-backdrop', hasStaticModal(modalsElement) ? 'static' : null);
    $(modalsElement).modal('show');
  });
// Bootstrap 5
import {Modal} from 'bootstrap';

const modalsElement = document.getElementById('laravel-livewire-modals');
const hasStaticModal = (el) => el.querySelector('.modal-content.modal-static') != null

Livewire.on('showBootstrapModal', () => {
    let modal = Modal.getInstance(modalsElement);

    if (!modal) {
        modalsElement.setAttribute('data-bs-backdrop', hasStaticModal(modalsElement) ? 'static' : null); 
        modal = new Modal(modalsElement);
    }

    modal.show();
});