ghosh / Micromodal

⭕ Tiny javascript library for creating accessible modal dialogs
https://micromodal.now.sh/
MIT License
3.54k stars 230 forks source link

onClose not called when provided to Micromodal.init #354

Open CoreyBurkhart opened 4 years ago

CoreyBurkhart commented 4 years ago

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"
mrdarkside commented 4 years ago
MicroModal.init({
  onClose: () => { console.log('close') }
})

no?

mattgaspar commented 4 years ago

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!

ara303 commented 4 years ago

@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.

OliverLSanz commented 2 years ago

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.