Skip to content

Commit

Permalink
Pressing Esc in a modal in a gadget only closes the modal. Closes rst…
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jan 3, 2017
1 parent 92ba7e9 commit 7a85a10
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions srcjs/modal.js
Expand Up @@ -27,13 +27,30 @@ exports.modal = {
});
}

$modal.on('keydown.shinymodal', function(e) {
// If we're listening for Esc, don't let the event propagate. See
// https://github.com/rstudio/shiny/issues/1453. The value of
// data("keyboard") needs to be checked inside the handler, because at
// the time that $modal.on() is called, the $("#shiny-modal") div doesn't
// yet exist.
if ($("#shiny-modal").data("keyboard") === false)
return;

if (e.keyCode === 27) {
e.stopPropagation();
e.preventDefault();
}
});

// Set/replace contents of wrapper with html.
exports.renderContent($modal, { html: html, deps: deps });
},

remove: function() {
const $modal = $('#shiny-modal-wrapper');

$modal.off('keydown.shinymodal');

// Look for a Bootstrap modal and if present, trigger hide event. This will
// trigger the hidden.bs.modal callback that we set in show(), which unbinds
// and removes the element.
Expand Down

0 comments on commit 7a85a10

Please sign in to comment.