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

Also filter out keypresses when focused on contenteditable elements #45

Open
crittermike opened this issue Jun 20, 2012 · 7 comments
Open

Comments

@crittermike
Copy link

I just overrode key.filter() to also ignore keypresses when the current element is contenteditable, using this code:

key.filter = function(event) {
  var tagName = (event.target || event.srcElement).tagName;
  var editable = (event.target || event.srcElement).getAttribute('contenteditable');
  return !(tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA' || editable);
}

I'm not sure if that's the best way to implement it, but it seems like this would be a good default, no?

@davidchambers
Copy link
Contributor

The element's isContentEditable property is possibly a better source of information, though I don't know how widely supported it is.

key.filter = function(event) {
  var el = event.target || event.srcElement;
  return !(el.isContentEditable || el.tagName == 'INPUT' ||
           el.tagName == 'SELECT' || el.tagName == 'TEXTAREA');
}

@focusaurus
Copy link

+1

@davidchambers
Copy link
Contributor

Would you accept a pull request for this change, @madrobby?

@ajb
Copy link

ajb commented Jan 7, 2015

👍 is there any reason this has been open for a year and half? I'm happy to PR if that's all it needs.

@madrobby
Copy link
Owner

madrobby commented Jan 7, 2015

@ajb not everyone needs this, that's why the filter function is easily overridable. I'd merge a PR with extensive tests tho. It needs detection of the browser supports isContentEditable, I have no idea about how widespread support is. Remember that kemaster should work on older browsers.

@ajb
Copy link

ajb commented Jan 7, 2015

Thanks -- to your credit, key.filter is very-well documented 😀. I'll see if I can whip something together...

@manoharank
Copy link

@madrobby Awesome library so far. 👍 to add contenteditable elements in the default filter.

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

6 participants