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

fix: KeyboardEvent.keyCode is deprecated #681

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

kerlon5
Copy link
Contributor

@kerlon5 kerlon5 commented Oct 25, 2022

use KeyboardEvent.code instead
it is used to fix camunda/camunda-modeler/2724

I'm not sure, do you need an old check by KeyboardEvent.keyCode? Then we can use triple check

@kerlon5
Copy link
Contributor Author

kerlon5 commented Oct 26, 2022

@barmac I can't add "needs review" label to PR

@barmac
Copy link
Member

barmac commented Oct 26, 2022

That is fine. We have an automation for this :)

@kerlon5
Copy link
Contributor Author

kerlon5 commented Oct 26, 2022

Do I need to add linked issue to this repo for tag automation?

@barmac
Copy link
Member

barmac commented Oct 26, 2022

It's OK, we don't need the label to review the PR.

Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I believe the general direction of the PR, it does not replace keyCode with supported properties in the whole codebase. Notice that SearchPad is left intact: https://github.com/bpmn-io/diagram-js/blob/develop/lib/features/search-pad/SearchPad.js#L94

lib/features/keyboard/KeyboardUtil.js Outdated Show resolved Hide resolved
@barmac
Copy link
Member

barmac commented Nov 8, 2022

I will look into this again this week. Sorry for delay.

Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand that keyCode is deprecated, and we don't support IE anymore, we shouldn't make changes which break the features for the old browsers.

If we are to merge the changes, we should check both the key and the code properties. Note that there are also some IE specifics which we could account for: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#examples

We could also keep support for keyCode but start using code in parallel to fix the problems with non-latin keyboards.

Also, ideally I'd like the features within the library to rely on isKey in keyboard util instead of having which, key etc. checks scattered around the codebase.

@@ -282,7 +282,7 @@ export default function Dragging(eventBus, canvas, selection, elementRegistry) {

function checkCancel(event) {

if (event.which === 27) {
if (event.code === 'Escape') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break the feature for IE entirely: https://caniuse.com/keyboardevent-code

@@ -93,45 +93,38 @@ SearchPad.prototype._bindEvents = function() {
// navigate results
listen(this._container, SearchPad.INPUT_SELECTOR, 'keydown', function(e) {

// up
if (e.keyCode === 38) {
if (e.code === 'ArrowUp') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break the feature for IE entirely: https://caniuse.com/keyboardevent-code

@nikku
Copy link
Member

nikku commented Nov 15, 2022

@barmac I believe we can ditch IE entirely now. New features we build (cf. #687) don't have the legacy in sight, too.

And if IE users wanted they can (1) stick to older versions of the toolkit or (2) roll their own compatibility layer.

@nikku nikku requested a review from barmac November 15, 2022 11:56
@nikku nikku added the needs review Review pending label Nov 15, 2022
This fixes the issue of not detecting key strokes on non-latin
keyboards.

BREAKING CHANGE:

* Keyboard-related features no longer use KeyboardEvent#keyCode.
  Use a polyfill (e.g. [keyboardevent-key-polyfill](https://www.npmjs.com/package/keyboardevent-key-polyfill) if you need to support old browsers.

Co-authored-by: Maciej Barelkowski <[email protected]>
Copy link
Member

@barmac barmac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I adjusted the PR and added a changelog update. Ready to merge.

@barmac
Copy link
Member

barmac commented Nov 15, 2022

So there is actually a polyfill for KeyboardEvent#key which I linked :)

@barmac barmac merged commit ff861b0 into bpmn-io:develop Nov 15, 2022
@bpmn-io-tasks bpmn-io-tasks bot removed the needs review Review pending label Nov 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Camunda Modeler Keyboard Shortcuts not working with non ENG keyboard layout
3 participants