atst/js/mixins/modal.js
dandds 457b1f9523 Detangle the MultiStepModalForm modal-open link from the modal.
In order to place modal forms in other places on the page (so that forms
are not nested) it's necessary to move MultiStepModalForm links out of
the component. They just need to refer to the correct modal.

This PR also makes changes to ensure that the active modal is being
unset everywhere correctly when a modal is closed.
2019-05-08 11:16:56 -04:00

46 lines
1.0 KiB
JavaScript

import ally from 'ally.js'
export default {
methods: {
closeModal: function(name) {
this.activeModal = null
this.$root.$emit('modalOpen', { isOpen: false, name: name })
if (this.allyHandler) this.allyHandler.disengage()
},
openModal: function(name) {
this.activeModal = name
this.$root.$emit('modalOpen', { isOpen: true, name: name })
const idSelector = `#${this.modalId}`
this.allyHandler = ally.maintain.disabled({
filter: idSelector,
})
},
// TODO: activeModal should be tracked on the root
handleModalOpen: function(event) {
if (!event.isOpen) {
this.activeModal = null
}
},
},
mounted: function() {
this.$root.$on('modalOpen', this.handleModalOpen)
},
data: function() {
// TODO: only the root component should know about the activeModal
return {
activeModal: null,
allyHandler: null,
}
},
computed: {
modalId: function() {
return !!this.activeModal ? `modal--${this.activeModal}` : null
},
},
}