[feat] back button closes modal
This commit is contained in:
@@ -1,3 +1,25 @@
|
||||
const filterfacet = (event) => {
|
||||
console.log(event);
|
||||
}
|
||||
import * as bootstrap from 'bootstrap';
|
||||
window.bootstrap = bootstrap;
|
||||
|
||||
|
||||
// trap browser back and close the modal if open
|
||||
const cardModal = document.getElementById('cardModal');
|
||||
// Push a new history state when the modal is shown
|
||||
cardModal.addEventListener('shown.bs.modal', () => {
|
||||
history.pushState({ modalOpen: true }, null, '#cardModal');
|
||||
});
|
||||
// Listen for the browser's back button (popstate event)
|
||||
window.addEventListener('popstate', (e) => {
|
||||
if (cardModal.classList.contains('show')) {
|
||||
const modalInstance = bootstrap.Modal.getInstance(cardModal);
|
||||
if (modalInstance) {
|
||||
modalInstance.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Trigger a back navigation when the modal is closed via its native controls (X, backdrop click)
|
||||
cardModal.addEventListener('hide.bs.modal', () => {
|
||||
if (history.state && history.state.modalOpen) {
|
||||
history.back();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user