Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: send file modal not working via keyboard #16607

Merged
merged 2 commits into from Feb 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 14 additions & 12 deletions app/ui-utils/client/lib/modal.js
Expand Up @@ -160,26 +160,23 @@ export const modal = {
if (!modalStack.length) {
return;
}

const instance = modalStack[modalStack.length - 1];

if (instance && instance.config && instance.config.confirmOnEnter && event.key === 'Enter') {
if (event.key === 'Escape') {
event.preventDefault();
event.stopPropagation();

if (instance.config.input) {
return instance.confirm($('.js-modal-input').val());
}

instance.confirm(true);
return;
instance.close();
}

if (event.key === 'Escape') {
if (instance && instance.confirmOnEnter && event.key === 'Enter') {
event.preventDefault();
event.stopPropagation();

instance.close();
if (instance.input) {
return instance.confirm($('.js-modal-input').val());
}

instance.confirm(true);
}
},
};
Expand Down Expand Up @@ -211,18 +208,22 @@ Template.rc_modal.helpers({
});

Template.rc_modal.onRendered(function() {
this.oldFocus = document.activeElement;
if (this.data.onRendered) {
this.data.onRendered();
}

if (this.data.input) {
$('.js-modal-input').focus();
$('.js-modal-input', this.firstNode).focus();
} else if (this.data.showConfirmButton && this.data.confirmOnEnter) {
$('.js-confirm', this.firstNode).focus();
}

this.data.closeOnEscape && document.addEventListener('keydown', modal.onKeyDown);
});

Template.rc_modal.onDestroyed(function() {
this.oldFocus && this.oldFocus.focus();
document.removeEventListener('keydown', modal.onKeyDown);
});

Expand All @@ -233,6 +234,7 @@ Template.rc_modal.events({
this.close();
},
'click .js-close'(e) {
e.preventDefault();
e.stopPropagation();
this.cancel();
},
Expand Down