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

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

Open
spencerlawrence36 opened this issue Nov 26, 2020 · 1 comment

Comments

@spencerlawrence36
Copy link

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

@MarketingPip
Copy link

@spencerlawrence36 - don't know if you're still using this library. But figured I would note this seems to be working now. 👍

Note: anyone looking to handle Mousetrap events on text areas add mousetrap class to the HTML element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants