GoogleChrome / dialog-polyfill

Polyfill for the HTML dialog element
BSD 3-Clause "New" or "Revised" License
2.45k stars 245 forks source link

pressing ESC during showModal sometimes doesnt close the dialog #45

Closed zmandel closed 9 years ago

zmandel commented 9 years ago

If a page already has a handler for "ESC", and you show a modal dialog, the "ESC" event is trapped by the previous handler and not by the dialog. In my case, I use this great polyfill in an open-source chrome extension: https://github.com/zmandel/Plus-for-Trello/blob/1c2fa9ca36327211834fd8f2933cfb47ad69ecf1/source/card.js#L360 and in that line you can see that I had to manually catch the keydown and close() That dialog code is injected into a trello "card" (trello.com) and without it Trello will close the card and leave my dialog floating. Not sure if this is specific with being on a chrome extension.

mfalken commented 9 years ago

Thanks for reporting. I think the polyfill doesn't go out of its way to be the "top" handler for keyboard presses. BTW, if this is for a Chrome extension, you can just use the native <dialog> instead of the polyfill, as Chrome supports <dialog>.

samthor commented 9 years ago

I'll take a look, but +1 to @mattto: if you're writing a Chrome extension, you don't need this polyfill at all.

zmandel commented 9 years ago

It depends on the version of chrome. Some people use older versions thus I use the polyfill