Micromodal icon indicating copy to clipboard operation
Micromodal copied to clipboard

onClose not called when provided to Micromodal.init

Open CoreyBurkhart opened this issue 4 years ago • 4 comments

Repo

MicroModal.init({
  onClose() { console.log('close') }
})

MicroModal.show('my-modal')
MicroModal.close('my-modal')

Expectation: "close" will be logged to the console Actual: Nothing is logged to the console

When I provide the config to show, onClose gets called properly

MicroModal.show('my-modal', {
  onClose() { console.log('close') }
})
MicroModal.close('my-modal') // logs "close"

CoreyBurkhart avatar Jul 10 '20 20:07 CoreyBurkhart

MicroModal.init({
  onClose: () => { console.log('close') }
})

no?

mrdarkside avatar Jul 24 '20 12:07 mrdarkside

Calling MicroModal.show('my-modal') seems to clear any configuration set from MicroModal.init({ options... }) A work around that seems to work is to not use init if you need to use show but then you can't use data-micromodal-trigger so you need to wire up your own event handlers. Or pass in the same options for init and show!

mattgaspar avatar Aug 27 '20 09:08 mattgaspar

@mattgaspar 's second workaround worked for me! I was doing init with a bunch of options I needed and then manually displaying my modal via show, only to discover none of my options were being used. It's really quite baffling that calling show or hide would nuke the config options.

It'd be vastly more intuitive and easy to work with this library if the configuration options were persistent and show or close didn't delete them.

ara303 avatar Sep 10 '20 00:09 ara303

It'd be vastly more intuitive and easy to work with this library if the configuration options were persistent and show or close didn't delete them.

I agree. Global configuration could be overridden with configuration passed to show. But if nothing is passed to show global configuration should be used instead.

OliverLSanz avatar Jun 26 '22 09:06 OliverLSanz