File tree Expand file tree Collapse file tree 3 files changed +74
-30
lines changed Expand file tree Collapse file tree 3 files changed +74
-30
lines changed Original file line number Diff line number Diff line change @@ -2,33 +2,39 @@ import KeyCode from 'rc-util/lib/KeyCode';
22
33/** keyCode Judgment function */
44export function isValidateOpenKey ( currentKeyCode : number ) : boolean {
5- return ! [
6- // System function button
7- KeyCode . ESC ,
8- KeyCode . SHIFT ,
9- KeyCode . BACKSPACE ,
10- KeyCode . TAB ,
11- KeyCode . WIN_KEY ,
12- KeyCode . ALT ,
13- KeyCode . META ,
14- KeyCode . WIN_KEY_RIGHT ,
15- KeyCode . CTRL ,
16- KeyCode . SEMICOLON ,
17- KeyCode . EQUALS ,
18- KeyCode . CAPS_LOCK ,
19- KeyCode . CONTEXT_MENU ,
20- // F1-F12
21- KeyCode . F1 ,
22- KeyCode . F2 ,
23- KeyCode . F3 ,
24- KeyCode . F4 ,
25- KeyCode . F5 ,
26- KeyCode . F6 ,
27- KeyCode . F7 ,
28- KeyCode . F8 ,
29- KeyCode . F9 ,
30- KeyCode . F10 ,
31- KeyCode . F11 ,
32- KeyCode . F12 ,
33- ] . includes ( currentKeyCode ) ;
5+ return (
6+ // Undefined for Edge bug:
7+ // https://github.com/ant-design/ant-design/issues/51292
8+ currentKeyCode &&
9+ // Other keys
10+ ! [
11+ // System function button
12+ KeyCode . ESC ,
13+ KeyCode . SHIFT ,
14+ KeyCode . BACKSPACE ,
15+ KeyCode . TAB ,
16+ KeyCode . WIN_KEY ,
17+ KeyCode . ALT ,
18+ KeyCode . META ,
19+ KeyCode . WIN_KEY_RIGHT ,
20+ KeyCode . CTRL ,
21+ KeyCode . SEMICOLON ,
22+ KeyCode . EQUALS ,
23+ KeyCode . CAPS_LOCK ,
24+ KeyCode . CONTEXT_MENU ,
25+ // F1-F12
26+ KeyCode . F1 ,
27+ KeyCode . F2 ,
28+ KeyCode . F3 ,
29+ KeyCode . F4 ,
30+ KeyCode . F5 ,
31+ KeyCode . F6 ,
32+ KeyCode . F7 ,
33+ KeyCode . F8 ,
34+ KeyCode . F9 ,
35+ KeyCode . F10 ,
36+ KeyCode . F11 ,
37+ KeyCode . F12 ,
38+ ] . includes ( currentKeyCode )
39+ ) ;
3440}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as React from 'react';
22import KeyCode from 'rc-util/lib/KeyCode' ;
33import Select from '../src' ;
44import { injectRunAllTimers , expectOpen , keyDown } from './utils/common' ;
5- import { fireEvent , render } from '@testing-library/react' ;
5+ import { act , fireEvent , render } from '@testing-library/react' ;
66
77describe ( 'Select.Accessibility' , ( ) => {
88 injectRunAllTimers ( jest ) ;
@@ -67,4 +67,39 @@ describe('Select.Accessibility', () => {
6767 . textContent ,
6868 ) . toEqual ( 'Light' ) ;
6969 } ) ;
70+
71+ // https://github.com/ant-design/ant-design/issues/51292
72+ it ( 'edge bug' , ( ) => {
73+ const { container } = render (
74+ < Select
75+ mode = "combobox"
76+ options = { [
77+ {
78+ value : '123' ,
79+ } ,
80+ {
81+ value : '1234' ,
82+ } ,
83+ {
84+ value : '12345' ,
85+ } ,
86+ ] }
87+ defaultValue = "123"
88+ /> ,
89+ ) ;
90+
91+ // Invalid key
92+ keyDown ( container . querySelector ( 'input' ) ! , undefined ) ;
93+ act ( ( ) => {
94+ jest . runAllTimers ( ) ;
95+ } ) ;
96+ expectOpen ( container , false ) ;
97+
98+ // Valid key
99+ keyDown ( container . querySelector ( 'input' ) ! , KeyCode . A ) ;
100+ act ( ( ) => {
101+ jest . runAllTimers ( ) ;
102+ } ) ;
103+ expectOpen ( container ) ;
104+ } ) ;
70105} ) ;
Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ export function injectRunAllTimers(jest: Jest) {
101101
102102export function keyDown ( element : HTMLElement , keyCode : number ) {
103103 const event = createEvent . keyDown ( element , { keyCode } ) ;
104+ Object . defineProperties ( event , {
105+ which : { get : ( ) => keyCode } ,
106+ } ) ;
104107
105108 act ( ( ) => {
106109 fireEvent ( element , event ) ;
You can’t perform that action at this time.
0 commit comments