File tree 3 files changed +74
-30
lines changed
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';
2
2
3
3
/** keyCode Judgment function */
4
4
export 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
+ ) ;
34
40
}
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import * as React from 'react';
2
2
import KeyCode from 'rc-util/lib/KeyCode' ;
3
3
import Select from '../src' ;
4
4
import { injectRunAllTimers , expectOpen , keyDown } from './utils/common' ;
5
- import { fireEvent , render } from '@testing-library/react' ;
5
+ import { act , fireEvent , render } from '@testing-library/react' ;
6
6
7
7
describe ( 'Select.Accessibility' , ( ) => {
8
8
injectRunAllTimers ( jest ) ;
@@ -67,4 +67,39 @@ describe('Select.Accessibility', () => {
67
67
. textContent ,
68
68
) . toEqual ( 'Light' ) ;
69
69
} ) ;
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
+ } ) ;
70
105
} ) ;
Original file line number Diff line number Diff line change @@ -101,6 +101,9 @@ export function injectRunAllTimers(jest: Jest) {
101
101
102
102
export function keyDown ( element : HTMLElement , keyCode : number ) {
103
103
const event = createEvent . keyDown ( element , { keyCode } ) ;
104
+ Object . defineProperties ( event , {
105
+ which : { get : ( ) => keyCode } ,
106
+ } ) ;
104
107
105
108
act ( ( ) => {
106
109
fireEvent ( element , event ) ;
You can’t perform that action at this time.
0 commit comments