Trumbowyg: Add link modal does not focus !

Created on 15 Apr 2019  路  7Comments  路  Source: Alex-D/Trumbowyg

Hello,

Deep testing Trumbowyg i'm impressed...

Version 2.15.2 with custom css
Test on Chrome, Opera, FireFox

Clicking on the "add link" (not minimal) button, modal opens and displays fields but cannot focus on URL text field.

So it's impossible to add a link.

Works on your demo with the same version...

Any idea ? How can i help ?

Best regards

question

Most helpful comment

Solved now.
In script openModal (remove css and change appendTo)

  var $modal = $('<div/>', {class: prefix + 'modal ' + prefix + 'fixed-top'})
  .css({
-    top: t.$box.offset().top + t.$btnPane.height(),
-    zIndex: 99999
  })
- .appendTo($(t.doc.body));
+ .appendTo($(t.$btnPane));

In css

  .trumbowyg-modal {
    position: absolute;
+   top: 100% !important;
+   z-index: +1;

So the modal is always related to the toolbar in any dialog depth.
;-)

Best regards

All 7 comments

Without demo page or steps to reproduce, I can't help.
Sorry :/

Hello,

I can give you access if required (on private)
This only happens when Trumbowyg is inside an ui dialog.
Seems the object is added outside the box (not related to its ancestors)

Regards

Solved now.
In script openModal (remove css and change appendTo)

  var $modal = $('<div/>', {class: prefix + 'modal ' + prefix + 'fixed-top'})
  .css({
-    top: t.$box.offset().top + t.$btnPane.height(),
-    zIndex: 99999
  })
- .appendTo($(t.doc.body));
+ .appendTo($(t.$btnPane));

In css

  .trumbowyg-modal {
    position: absolute;
+   top: 100% !important;
+   z-index: +1;

So the modal is always related to the toolbar in any dialog depth.
;-)

Best regards

Thanks so much @Yves-K! This is exactly the bug that we were running into and your fix works great! Kudos! The problem was the same. We have a trumbowyg editor initialized inside a bootstrap modal. We weren't able to interact with the add link or add image dialogs until trying this fix!

On closer examination, this is not a bug with trumbowyg but rather an issue with the Bootstrap modal enforcing focus. This answer from stack overflow shows how to fix it: https://stackoverflow.com/a/43104663/4531155.

For Bootstrap 3 modals:

$.fn.modal.Constructor.prototype.enforceFocus = function() {
  var $modalElement = this.$element;
  $(document).on('focusin.modal',function(e) {
    if ($modalElement[0] !== e.target
      && !$modalElement.has(e.target).length
      && $(e.target).parentsUntil('*[role="dialog"]').length === 0) {
      $modalElement.focus();
    }
  });
};

I confirm that the solution provided by @Yves-K is working well. In my case, (same as @rsmithlal ) I was using the text editor inside a Bootstrap 4 Modal. With this tweak works fine. However I had to change the trumbowyg-modal-button css class because it was shown with opacity.

I've found another way around this. I had this problem with the image plugin. Inside of the bootstrap 4 modal shown event.

$("#messagemodal").on('shown.bs.modal', function () {
$(document).off('focusin.modal');
});

worked like a charm!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Droeftoeter picture Droeftoeter  路  5Comments

btecu picture btecu  路  3Comments

tonvanalebeek picture tonvanalebeek  路  6Comments

Jeong-YeongMin picture Jeong-YeongMin  路  5Comments

vasileioslaios picture vasileioslaios  路  5Comments