-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Simplify key codes expression in Tags component #4248
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @stesel thanks for the code! The PR looks nice.
A question: would you be willing to go a step further and switch from event.keyCode
, which is deprecated, to use event.key
, see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.keyCode != KEYS.RIGHT && | ||
e.keyCode != KEYS.TAB | ||
) { | ||
} else if ((e.keyCode < 65 || e.keyCode > 90) && !COMBO_KEYS.includes(e.keyCode)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we line wrap this conditional? It's just a bit long for reading on one line in my opinion. 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, easy :)
Sure, I've migrated to event.key. Now I have questions, do we need fallbacks for old browsers witch doesn't support |
@stesel I don't think so, I'm looking at both https://caniuse.com/#feat=keyboardevent-key and https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Browser_compatibility and I think we're fine. It's obviously open to discussion... |
@rhymesfor thank you for response! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @stesel! Thanks for the PR! 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, great work!
* Simplifying this key codes expression in Tags component * Refactor KeyboardEvent keyCode to key * Simplify cyrillic letter regexp * Wrap condition in 2 lines
What type of PR is this? (check all applicable)
Description
Move combination key codes to separate const in
tags.jsx
file.Add test for checking
preventDefault
inhandleKeyDown
method.Suggestions comes form codeclimate.
https://codeclimate.com/github/thepracticaldev/dev.to/app/javascript/shared/components/tags.jsx/source#issue-a087ee1bf368783e621a0b4563a3aaeb
Related Tickets & Documents
https://codeclimate.com/github/thepracticaldev/dev.to/app/javascript/shared/components/tags.jsx/source#issue-a087ee1bf368783e621a0b4563a3aaeb
Mobile & Desktop Screenshots/Recordings (if there are UI changes)
Added to documentation?
[optional] What gif best describes this PR or how it makes you feel?