#494·mousetrap

Adding mousetrap to textarea class does not work, Mousetrap.prototype.stopCallback does work

Author: spencerlawrence36Created Nov 26, 2020Updated Dec 9, 2022

Intended behavior: enable shortcut while user is in text area (in focus) Attempted solution:

          <div class="col-12">
              <textarea class="form-control mousetrap" id="my-text-area" name="user-input">
              </textarea>
          </div>

Reference: Section I in the docs Expected: Shortcut clicks button Actual: Nothing happens

There's a submit button elsewhere. I can post the code but the shortcut works fine when the user is outside of the text area, or if I use stopCallback as below.

Shortcut:

  Mousetrap.bind('ctrl+enter', function() {
      $('#submit-button').trigger('click');
  });

I was able to enable the shortcut functionality while the user is in the text area using this:

   Mousetrap.prototype.stopCallback = function () {
     return false;
}

Reference: https://stackoverflow.com/questions/21013866/mousetrap-bind-is-not-working-when-field-is-in-focus

I would prefer not to disable the default (shortcut doesn't work when field in focus) globally. It seems that there's a bug in the way the mousetrap class works