Skip to content

Commit bfbdbbe

Browse files
committed
refactor(defaultTheme): remove legacy compat keydown event prop keyCode
1 parent a171bca commit bfbdbbe

File tree

1 file changed

+48
-102
lines changed

1 file changed

+48
-102
lines changed

src/tpl/defaultTheme/frontend/index.js

Lines changed: 48 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,17 @@
117117
doFilter();
118118
};
119119

120-
var ENTER_CODE = 13;
121-
var ESCAPE_CODE = 27;
122-
123120
input.addEventListener('keydown', function (e) {
124-
if (e.key) {
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;
135-
}
136-
} else if (e.keyCode) {
137-
switch (e.keyCode) {
138-
case ENTER_CODE:
139-
onEnter();
140-
e.preventDefault();
141-
break;
142-
case ESCAPE_CODE:
143-
onEscape();
144-
e.preventDefault();
145-
break;
146-
}
121+
switch (e.key) {
122+
case Enter:
123+
onEnter();
124+
e.preventDefault();
125+
break;
126+
case Escape:
127+
case Esc:
128+
onEscape();
129+
e.preventDefault();
130+
break;
147131
}
148132
}, false);
149133

@@ -346,20 +330,16 @@
346330
return matchKeyA;
347331
}
348332

349-
var UP = 'Up';
350-
var DOWN = 'Down';
351-
var LEFT = 'Left';
352-
var RIGHT = 'Right';
353-
354333
var ARROW_UP = 'ArrowUp';
355334
var ARROW_DOWN = 'ArrowDown';
356335
var ARROW_LEFT = 'ArrowLeft';
357336
var ARROW_RIGHT = 'ArrowRight';
358337

359-
var ARROW_UP_CODE = 38;
360-
var ARROW_DOWN_CODE = 40;
361-
var ARROW_LEFT_CODE = 37;
362-
var ARROW_RIGHT_CODE = 39;
338+
// IE/ClassicEdge specific key
339+
var UP = 'Up';
340+
var DOWN = 'Down';
341+
var LEFT = 'Left';
342+
var RIGHT = 'Right';
363343

364344
var SKIP_TAGS = ['INPUT', 'BUTTON', 'TEXTAREA'];
365345

@@ -431,75 +411,41 @@
431411
return;
432412
}
433413

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

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

0 commit comments

Comments
 (0)