8000 Fixed a bug with focusing inputs inside a modal in IE · django-cms/django-cms@c9661ea · GitHub
[go: up one dir, main page]

Skip to content

Commit c9661ea

Browse files
committed
Fixed a bug with focusing inputs inside a modal in IE
1 parent 7ed2907 commit c9661ea

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CHANGELOG.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
users with change permissions, unless the ``preview`` GET parameter is used.
99
* Fixed "Expand all / Collapse all" not reflecting real state of the placeholder tree
1010
* Fixed a bug where Aliased plugins would render even if their host page was unpublished.
11+
* Fixed a bug where focusing inputs in modal would require 2 clicks in some browsers
1112

1213

1314
=== 3.4.5 (2017-10-12) ===

cms/static/cms/js/dist/3.4.3/bundle.toolbar.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cms/static/cms/js/modules/cms.modal.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,9 +943,12 @@ class Modal {
943943
return;
944944
}
945945

946-
body.attr('tabindex', '0');
946+
// tabindex is required for keyboard navigation
947+
// body.attr('tabindex', '0');
947948
iframe.on('focus', function() {
948-
body.focus();
949+
if (this.contentWindow) {
950+
this.contentWindow.focus();
951+
}
949952
});
950953

951954
Modal._setupCtrlEnterSave(document);
@@ -1093,6 +1096,21 @@ class Modal {
10931096
if (contents.find('.object-tools').length) {
10941097
contents.find('#content').css('padding-top', 38); // eslint-disable-line
10951098
}
1099+
1100+
// this is required for IE11. we assume that when the modal is opened the user is going to interact
1101+
// with it. if we don't focus the body directly the next time the user clicks on a field inside
1102+
// the iframe the focus will be stolen by body thus requiring two clicks. this immediately focuses the
1103+
// iframe body on load except if something is already focused there
1104+
// (django tries to focus first field by default)
1105+
setTimeout(() => {
1106+
if (!iframe[0] || !iframe[0].contentDocument || !iframe[0].contentDocument.documentElement) {
1107+
return;
1108+
}
1109+
if ($(iframe[0].contentDocument.documentElement).find(':focus').length) {
1110+
return;
1111+
}
1112+
iframe.trigger('focus');
1113+
}, 0); // eslint-disable-line
10961114
}
10971115

10981116
that._attachContentPreservingHandlers(iframe);

0 commit comments

Comments
 (0)
0