@@ -5,6 +5,7 @@ export default class Combobox {
5
5
keyboardEventHandler : ( event : KeyboardEvent ) => void
6
6
compositionEventHandler : ( event : Event ) => void
7
7
inputHandler : ( event : Event ) => void
8
+ ctrlBindings : boolean
8
9
9
10
constructor ( input : HTMLTextAreaElement | HTMLInputElement , list : HTMLElement ) {
10
11
this . input = input
@@ -15,9 +16,9 @@ export default class Combobox {
15
16
list . id = `combobox-${ Math . random ( ) . toString ( ) . slice ( 2 , 6 ) } `
16
17
}
17
18
18
- const ctrlBindings = ! ! navigator . userAgent . match ( / M a c i n t o s h / )
19
+ this . ctrlBindings = ! ! navigator . userAgent . match ( / M a c i n t o s h / )
19
20
20
- this . keyboardEventHandler = event => keyboardBindings ( event , this , ctrlBindings )
21
+ this . keyboardEventHandler = event => keyboardBindings ( event , this )
21
22
this . compositionEventHandler = event => trackComposition ( event , this )
22
23
this . inputHandler = this . clearSelection . bind ( this )
23
24
input . setAttribute ( 'role' , 'combobox' )
@@ -95,9 +96,9 @@ export default class Combobox {
95
96
}
96
97
}
97
98
98
- function keyboardBindings ( event : KeyboardEvent , combobox : Combobox , ctrlBindings : boolean ) {
99
+ function keyboardBindings ( event : KeyboardEvent , combobox : Combobox ) {
99
100
if ( event . shiftKey || event . metaKey || event . altKey ) return
100
- if ( ! ctrlBindings && event . ctrlKey ) return
101
+ if ( ! combobox . ctrlBindings && event . ctrlKey ) return
101
102
if ( combobox . isComposing ) return
102
103
103
104
switch ( event . key ) {
@@ -119,13 +120,13 @@ function keyboardBindings(event: KeyboardEvent, combobox: Combobox, ctrlBindings
119
120
event . preventDefault ( )
120
121
break
121
122
case 'n' :
122
- if ( ctrlBindings && event . ctrlKey ) {
123
+ if ( combobox . ctrlBindings && event . ctrlKey ) {
123
124
combobox . navigate ( 1 )
124
125
event . preventDefault ( )
125
126
}
126
127
break
127
128
case 'p' :
128
- if ( ctrlBindings && event . ctrlKey ) {
129
+ if ( combobox . ctrlBindings && event . ctrlKey ) {
129
130
combobox . navigate ( - 1 )
130
131
event . preventDefault ( )
131
132
}
0 commit comments