Skip to content

Commit 6fa3894

Browse files
committed
refactor(defaultTheme): remove legacy compat keydown event prop keyCode
1 parent 8672a82 commit 6fa3894

File tree

1 file changed

+44
-98
lines changed

1 file changed

+44
-98
lines changed

src/tpl/defaultTheme/frontend/index.js

Lines changed: 44 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -121,33 +121,17 @@
121121
doFilter();
122122
};
123123

124-
var ENTER_CODE = 13;
125-
var ESCAPE_CODE = 27;
126-
127124
input.addEventListener('keydown', function (e) {
128-
if (e.key) {
129-
switch (e.key) {
130-
case Enter:
131-
onEnter();
132-
e.preventDefault();
133-
break;
134-
case Escape:
135-
case Esc:
136-
onEscape();
137-
e.preventDefault();
138-
break;
139-
}
140-
} else if (e.keyCode) {
141-
switch (e.keyCode) {
142-
case ENTER_CODE:
143-
onEnter();
144-
e.preventDefault();
145-
break;
146-
case ESCAPE_CODE:
147-
onEscape();
148-
e.preventDefault();
149-
break;
150-
}
125+
switch (e.key) {
126+
case Enter:
127+
onEnter();
128+
e.preventDefault();
129+
break;
130+
case Escape:
131+
case Esc:
132+
onEscape();
133+
e.preventDefault();
134+
break;
151135
}
152136
}, false);
153137

@@ -350,6 +334,7 @@
350334
return matchKeyA;
351335
}
352336

337+
// IE specific key
353338
var UP = 'Up';
354339
var DOWN = 'Down';
355340
var LEFT = 'Left';
@@ -360,11 +345,6 @@
360345
var ARROW_LEFT = 'ArrowLeft';
361346
var ARROW_RIGHT = 'ArrowRight';
362347

363-
var ARROW_UP_CODE = 38;
364-
var ARROW_DOWN_CODE = 40;
365-
var ARROW_LEFT_CODE = 37;
366-
var ARROW_RIGHT_CODE = 39;
367-
368348
var SKIP_TAGS = ['INPUT', 'BUTTON', 'TEXTAREA'];
369349

370350
var PLATFORM = navigator.platform;
@@ -435,75 +415,41 @@
435415
return;
436416
}
437417

438-
if (e.key) {
439-
if (canArrowMove(e)) {
440-
switch (e.key) {
441-
case LEFT:
442-
case ARROW_LEFT:
443-
if (isToEnd(e)) {
444-
return getFirstFocusableSibling(pathList);
445-
} else {
446-
return getFocusableSibling(pathList, true);
447-
}
448-
case RIGHT:
449-
case ARROW_RIGHT:
450-
if (isToEnd(e)) {
451-
return getLastFocusableSibling(pathList);
452-
} else {
453-
return getFocusableSibling(pathList, false);
454-
}
455-
case UP:
456-
case ARROW_UP:
457-
if (isToEnd(e)) {
458-
return getFirstFocusableSibling(itemList);
459-
} else {
460-
return getFocusableSibling(itemList, true);
461-
}
462-
case DOWN:
463-
case ARROW_DOWN:
464-
if (isToEnd(e)) {
465-
return getLastFocusableSibling(itemList);
466-
} else {
467-
return getFocusableSibling(itemList, false);
468-
}
469-
}
470-
}
471-
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.key.length === 1) {
472-
return lookup(itemList, e.key, e.shiftKey);
473-
}
474-
} else if (e.keyCode) {
475-
if (canArrowMove(e)) {
476-
switch (e.keyCode) {
477-
case ARROW_LEFT_CODE:
478-
if (isToEnd(e)) {
479-
return getFirstFocusableSibling(pathList);
480-
} else {
481-
return getFocusableSibling(pathList, true);
482-
}
483-
case ARROW_RIGHT_CODE:
484-
if (isToEnd(e)) {
485-
return getLastFocusableSibling(pathList);
486-
} else {
487-
return getFocusableSibling(pathList, false);
488-
}
489-
case ARROW_UP_CODE:
490-
if (isToEnd(e)) {
491-
return getFirstFocusableSibling(itemList);
492-
} else {
493-
return getFocusableSibling(itemList, true);
494-
}
495-
case ARROW_DOWN_CODE:
496-
if (isToEnd(e)) {
497-
return getLastFocusableSibling(itemList);
498-
} else {
499-
return getFocusableSibling(itemList, false);
500-
}
501-
}
502-
}
503-
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.keyCode >= 32 && e.keyCode <= 126) {
504-
return lookup(itemList, String.fromCharCode(e.keyCode), e.shiftKey);
418+
if (canArrowMove(e)) {
419+
switch (e.key) {
420+
case LEFT:
421+
case ARROW_LEFT:
422+
if (isToEnd(e)) {
423+
return getFirstFocusableSibling(pathList);
424+
} else {
425+
return getFocusableSibling(pathList, true);
426+
}
427+
case RIGHT:
428+
case ARROW_RIGHT:
429+
if (isToEnd(e)) {
430+
return getLastFocusableSibling(pathList);
431+
} else {
432+
return getFocusableSibling(pathList, false);
433+
}
434+
case UP:
435+
case ARROW_UP:
436+
if (isToEnd(e)) {
437+
return getFirstFocusableSibling(itemList);
438+
} else {
439+
return getFocusableSibling(itemList, true);
440+
}
441+
case DOWN:
442+
case ARROW_DOWN:
443+
if (isToEnd(e)) {
444+
return getLastFocusableSibling(itemList);
445+
} else {
446+
return getFocusableSibling(itemList, false);
447+
}
505448
}
506449
}
450+
if (!e.ctrlKey && (!e.altKey || IS_MAC_PLATFORM) && !e.metaKey && e.key.length === 1) {
451+
return lookup(itemList, e.key, e.shiftKey);
452+
}
507453
}
508454

509455
document.addEventListener('keydown', function (e) {

0 commit comments

Comments
 (0)