Nycto / PicoModal

A small, self-contained JavaScript modal library. Plain, vanilla JS.
MIT License
241 stars 42 forks source link

Multiple instances of the same modal can be created #8

Closed heidid closed 10 years ago

heidid commented 10 years ago

Since a page can be navigated by keyboard, pressing [enter] or [space] will continue to create more instances of the same modal. For example, attach the modal to an onclick event listener, and pressing [enter] to click the button multiple times will result in multiple modals overlayed on top of each other. A solution would be to change the focus to the modal when created.

Nycto commented 10 years ago

What version are you using? 2.0.1 doesn't set focus properly, but it also doesn't open multiple versions of the same modal:

http://jsfiddle.net/2s95h/

heidid commented 10 years ago

Ah, I see my problem. I was initiating a new picoModal every time (fiddle), so of course multiple modals would appear. Thanks.

Nycto commented 10 years ago

Followup: I added a section to the readme to make sure this use case is clear: 84ebf91259a12cd8380921fd43bcff658de63002