@@ -38,6 +38,7 @@ import {
38
38
getComboboxes ,
39
39
assertCombobox ,
40
40
ComboboxMode ,
41
+ assertNotActiveComboboxOption ,
41
42
} from '../../test-utils/accessibility-assertions'
42
43
import { Transition } from '../transitions/transition'
43
44
@@ -579,7 +580,7 @@ describe('Rendering', () => {
579
580
} )
580
581
assertComboboxList ( {
581
582
state : ComboboxState . Visible ,
582
- textContent : JSON . stringify ( { active : false , selected : false , disabled : false } ) ,
583
+ textContent : JSON . stringify ( { active : true , selected : false , disabled : false } ) ,
583
584
} )
584
585
} )
585
586
)
@@ -667,16 +668,13 @@ describe('Rendering composition', () => {
667
668
668
669
// Verify correct classNames
669
670
expect ( '' + options [ 0 ] . classList ) . toEqual (
670
- JSON . stringify ( { active : false , selected : false , disabled : false } )
671
+ JSON . stringify ( { active : true , selected : false , disabled : false } )
671
672
)
672
673
expect ( '' + options [ 1 ] . classList ) . toEqual (
673
674
JSON . stringify ( { active : false , selected : false , disabled : true } )
674
675
)
675
676
expect ( '' + options [ 2 ] . classList ) . toEqual ( 'no-special-treatment' )
676
677
677
- // Double check that nothing is active
678
- assertNoActiveComboboxOption ( getComboboxInput ( ) )
679
-
680
678
// Make the first option active
681
679
await press ( Keys . ArrowDown )
682
680
@@ -841,7 +839,7 @@ describe('Composition', () => {
841
839
} )
842
840
assertComboboxList ( {
843
841
state : ComboboxState . Visible ,
844
- textContent : JSON . stringify ( { active : false , selected : false , disabled : false } ) ,
842
+ textContent : JSON . stringify ( { active : true , selected : false , disabled : false } ) ,
845
843
} )
846
844
847
845
await click ( getComboboxButton ( ) )
@@ -905,7 +903,7 @@ describe('Keyboard interactions', () => {
905
903
expect ( options ) . toHaveLength ( 3 )
906
904
options . forEach ( ( option ) => assertComboboxOption ( option , { selected : false } ) )
907
905
908
- assertNoActiveComboboxOption ( )
906
+ assertActiveComboboxOption ( options [ 0 ] )
909
907
assertNoSelectedComboboxOption ( )
910
908
} )
911
909
)
@@ -1191,7 +1189,7 @@ describe('Keyboard interactions', () => {
1191
1189
let options = getComboboxOptions ( )
1192
1190
expect ( options ) . toHaveLength ( 3 )
1193
1191
options . forEach ( ( option ) => assertComboboxOption ( option ) )
1194
- assertNoActiveComboboxOption ( )
1192
+ assertActiveComboboxOption ( options [ 0 ] )
1195
1193
} )
1196
1194
)
1197
1195
@@ -1434,7 +1432,7 @@ describe('Keyboard interactions', () => {
1434
1432
options . forEach ( ( option ) => assertComboboxOption ( option ) )
1435
1433
1436
1434
// Verify that the first combobox option is active
1437
- assertNoActiveComboboxOption ( )
1435
+ assertActiveComboboxOption ( options [ 0 ] )
1438
1436
} )
1439
1437
)
1440
1438
@@ -2133,7 +2131,7 @@ describe('Keyboard interactions', () => {
2133
2131
options . forEach ( ( option ) => assertComboboxOption ( option ) )
2134
2132
2135
2133
// Verify that the first combobox option is active
2136
- assertNoActiveComboboxOption ( )
2134
+ assertActiveComboboxOption ( options [ 0 ] )
2137
2135
} )
2138
2136
)
2139
2137
@@ -2272,7 +2270,7 @@ describe('Keyboard interactions', () => {
2272
2270
let options = getComboboxOptions ( )
2273
2271
expect ( options ) . toHaveLength ( 3 )
2274
2272
options . forEach ( ( option ) => assertComboboxOption ( option ) )
2275
- assertNoActiveComboboxOption ( )
2273
+ assertActiveComboboxOption ( options [ 0 ] )
2276
2274
2277
2275
// We should be able to go down once
2278
2276
await press ( Keys . ArrowDown )
@@ -2322,7 +2320,7 @@ describe('Keyboard interactions', () => {
2322
2320
let options = getComboboxOptions ( )
2323
2321
expect ( options ) . toHaveLength ( 3 )
2324
2322
options . forEach ( ( option ) => assertComboboxOption ( option ) )
2325
- assertNoActiveComboboxOption ( )
2323
+ assertActiveComboboxOption ( options [ 1 ] )
2326
2324
2327
2325
// We should be able to go down once
2328
2326
await press ( Keys . ArrowDown )
@@ -2362,7 +2360,7 @@ describe('Keyboard interactions', () => {
2362
2360
let options = getComboboxOptions ( )
2363
2361
expect ( options ) . toHaveLength ( 3 )
2364
2362
options . forEach ( ( option ) => assertComboboxOption ( option ) )
2365
- assertNoActiveComboboxOption ( )
2363
+ assertActiveComboboxOption ( options [ 2 ] )
2366
2364
2367
2365
// Open combobox
2368
2366
await press ( Keys . ArrowDown )
@@ -2596,7 +2594,7 @@ describe('Keyboard interactions', () => {
2596
2594
let options = getComboboxOptions ( )
2597
2595
expect ( options ) . toHaveLength ( 3 )
2598
2596
options . forEach ( ( option ) => assertComboboxOption ( option ) )
2599
- assertNoActiveComboboxOption ( )
2597
+ assertActiveComboboxOption ( options [ 2 ] )
2600
2598
2601
2599
// Going up or down should select the single available option
2602
2600
await press ( Keys . ArrowUp )
@@ -2689,8 +2687,8 @@ describe('Keyboard interactions', () => {
2689
2687
2690
2688
let options = getComboboxOptions ( )
2691
2689
2692
- // We should have no option selected
2693
- assertNoActiveComboboxOption ( )
2690
+ // We should be on the first non-disabled option
2691
+ assertActiveComboboxOption ( options [ 0 ] )
2694
2692
2695
2693
// We should be able to go to the last option
2696
2694
await press ( Keys . End )
@@ -2723,8 +2721,8 @@ describe('Keyboard interactions', () => {
2723
2721
2724
2722
let options = getComboboxOptions ( )
2725
2723
2726
- // We should have no option selected
2727
- assertNoActiveComboboxOption ( )
2724
+ // We should be on the first non-disabled option
2725
+ assertActiveComboboxOption ( options [ 0 ] )
2728
2726
2729
2727
// We should be able to go to the last non-disabled option
2730
2728
await press ( Keys . End )
@@ -2757,13 +2755,14 @@ describe('Keyboard interactions', () => {
2757
2755
// Open combobox
2758
2756
await click ( getComboboxButton ( ) )
2759
2757
2760
- // We opened via click, we don't have an active option
2761
- assertNoActiveComboboxOption ( )
2758
+ let options = getComboboxOptions ( )
2762
2759
2763
- // We should not be able to go to the end
2760
+ // We should be on the first non-disabled option
2761
+ assertActiveComboboxOption ( options [ 0 ] )
2762
+
2763
+ // We should not be able to go to the end (no-op)
2764
2764
await press ( Keys . End )
2765
2765
2766
- let options = getComboboxOptions ( )
2767
2766
assertActiveComboboxOption ( options [ 0 ] )
2768
2767
} )
2769
2768
)
@@ -2828,7 +2827,7 @@ describe('Keyboard interactions', () => {
2828
2827
let options = getComboboxOptions ( )
2829
2828
2830
2829
// We should be on the first option
2831
- assertNoActiveComboboxOption ( )
2830
+ assertActiveComboboxOption ( options [ 0 ] )
2832
2831
2833
2832
// We should be able to go to the last option
2834
2833
await press ( Keys . PageDown )
@@ -2864,8 +2863,8 @@ describe('Keyboard interactions', () => {
2864
2863
2865
2864
let options = getComboboxOptions ( )
2866
2865
2867
- // We should have nothing active
2868
- assertNoActiveComboboxOption ( )
2866
+ // We should be on the first non-disabled option
2867
+ assertActiveComboboxOption ( options [ 0 ] )
2869
2868
2870
2869
// We should be able to go to the last non-disabled option
2871
2870
await press ( Keys . PageDown )
@@ -2898,13 +2897,14 @@ describe('Keyboard interactions', () => {
2898
2897
// Open combobox
2899
2898
await click ( getComboboxButton ( ) )
2900
2899
2901
- // We opened via click, we don't have an active option
2902
- assertNoActiveComboboxOption ( )
2900
+ let options = getComboboxOptions ( )
2901
+
2902
+ // We should be on the first non-disabled option
2903
+ assertActiveComboboxOption ( options [ 0 ] )
2903
2904
2904
2905
// We should not be able to go to the end
2905
2906
await press ( Keys . PageDown )
2906
2907
2907
- let options = getComboboxOptions ( )
2908
2908
assertActiveComboboxOption ( options [ 0 ] )
2909
2909
} )
2910
2910
)
@@ -3003,14 +3003,14 @@ describe('Keyboard interactions', () => {
3003
3003
// Open combobox
3004
3004
await click ( getComboboxButton ( ) )
3005
3005
3006
- // We opened via click, we don't have an active option
3007
- assertNoActiveComboboxOption ( )
3006
+ let options = getComboboxOptions ( )
3007
+
3008
+ // We should be on the first non-disabled option
3009
+ assertActiveComboboxOption ( options [ 2 ] )
3008
3010
3009
3011
// We should not be able to go to the end
3010
3012
await press ( Keys . Home )
3011
3013
3012
- let options = getComboboxOptions ( )
3013
-
3014
3014
// We should be on the first non-disabled option
3015
3015
assertActiveComboboxOption ( options [ 2 ] )
3016
3016
} )
@@ -3041,13 +3041,14 @@ describe('Keyboard interactions', () => {
3041
3041
// Open combobox
3042
3042
await click ( getComboboxButton ( ) )
3043
3043
3044
- // We opened via click, we don't have an active option
3045
- assertNoActiveComboboxOption ( )
3044
+ let options = getComboboxOptions ( )
3045
+
3046
+ // We should be on the last option
3047
+ assertActiveComboboxOption ( options [ 3 ] )
3046
3048
3047
3049
// We should not be able to go to the end
3048
3050
await press ( Keys . Home )
3049
3051
3050
- let options = getComboboxOptions ( )
3051
3052
assertActiveComboboxOption ( options [ 3 ] )
3052
3053
} )
3053
3054
)
@@ -3146,15 +3147,14 @@ describe('Keyboard interactions', () => {
3146
3147
// Open combobox
3147
3148
await click ( getComboboxButton ( ) )
3148
3149
3149
- // We opened via click, we don't have an active option
3150
- assertNoActiveComboboxOption ( )
3150
+ let options = getComboboxOptions ( )
3151
3151
3152
- // We should not be able to go to the end
3153
- await press ( Keys . PageUp )
3152
+ // We opened via click, we default to the first non-disabled option
3153
+ assertActiveComboboxOption ( options [ 2 ] )
3154
3154
3155
- let options = getComboboxOptions ( )
3155
+ // We should not be able to go to the end (no-op — already there)
3156
+ await press ( Keys . PageUp )
3156
3157
3157
- // We should be on the first non-disabled option
3158
3158
assertActiveComboboxOption ( options [ 2 ] )
3159
3159
} )
3160
3160
)
@@ -3184,13 +3184,14 @@ describe('Keyboard interactions', () => {
3184
3184
// Open combobox
3185
3185
await click ( getComboboxButton ( ) )
3186
3186
3187
- // We opened via click, we don't have an active option
3188
- assertNoActiveComboboxOption ( )
3187
+ let options = getComboboxOptions ( )
3189
3188
3190
- // We should not be able to go to the end
3189
+ // We opened via click, we default to the first non-disabled option
3190
+ assertActiveComboboxOption ( options [ 3 ] )
3191
+
3192
+ // We should not be able to go to the end (no-op — already there)
3191
3193
await press ( Keys . PageUp )
3192
3194
3193
- let options = getComboboxOptions ( )
3194
3195
assertActiveComboboxOption ( options [ 3 ] )
3195
3196
} )
3196
3197
)
@@ -4019,7 +4020,7 @@ describe('Mouse interactions', () => {
4019
4020
let options = getComboboxOptions ( )
4020
4021
4021
4022
await mouseMove ( options [ 1 ] )
4022
- assertNoActiveComboboxOption ( )
4023
+ assertNotActiveComboboxOption ( options [ 1 ] )
4023
4024
} )
4024
4025
)
4025
4026
@@ -4048,8 +4049,8 @@ describe('Mouse interactions', () => {
4048
4049
// Try to hover over option 1, which is disabled
4049
4050
await mouseMove ( options [ 1 ] )
4050
4051
4051
- // We should not have an active option now
4052
- assertNoActiveComboboxOption ( )
4052
+ // We should not have option 1 as the active option now
4053
+ assertNotActiveComboboxOption ( options [ 1 ] )
4053
4054
} )
4054
4055
)
4055
4056
@@ -4120,10 +4121,10 @@ describe('Mouse interactions', () => {
4120
4121
4121
4122
// Try to hover over option 1, which is disabled
4122
4123
await mouseMove ( options [ 1 ] )
4123
- assertNoActiveComboboxOption ( )
4124
+ assertNotActiveComboboxOption ( options [ 1 ] )
4124
4125
4125
4126
await mouseLeave ( options [ 1 ] )
4126
- assertNoActiveComboboxOption ( )
4127
+ assertNotActiveComboboxOption ( options [ 1 ] )
4127
4128
} )
4128
4129
)
4129
4130
@@ -4216,9 +4217,10 @@ describe('Mouse interactions', () => {
4216
4217
4217
4218
let options = getComboboxOptions ( )
4218
4219
4219
- // We should be able to click the first option
4220
+ // We should not be able to click the disabled option
4220
4221
await click ( options [ 1 ] )
4221
4222
assertComboboxList ( { state : ComboboxState . Visible } )
4223
+ assertNotActiveComboboxOption ( options [ 1 ] )
4222
4224
assertActiveElement ( getComboboxInput ( ) )
4223
4225
expect ( handleChange ) . toHaveBeenCalledTimes ( 0 )
4224
4226
@@ -4228,8 +4230,10 @@ describe('Mouse interactions', () => {
4228
4230
// Open combobox again
4229
4231
await click ( getComboboxButton ( ) )
4230
4232
4231
- // Verify the active option is non existing
4232
- assertNoActiveComboboxOption ( )
4233
+ options = getComboboxOptions ( )
4234
+
4235
+ // Verify the active option is not the disabled one
4236
+ assertNotActiveComboboxOption ( options [ 1 ] )
4233
4237
} )
4234
4238
)
4235
4239
@@ -4261,10 +4265,10 @@ describe('Mouse interactions', () => {
4261
4265
4262
4266
let options = getComboboxOptions ( )
4263
4267
4264
- // Verify that nothing is active yet
4265
- assertNoActiveComboboxOption ( )
4268
+ // Verify that the first item is active
4269
+ assertActiveComboboxOption ( options [ 0 ] )
4266
4270
4267
- // We should be able to focus the first option
4271
+ // We should be able to focus the second option
4268
4272
await focus ( options [ 1 ] )
4269
4273
assertActiveComboboxOption ( options [ 1 ] )
4270
4274
} )
@@ -4296,7 +4300,7 @@ describe('Mouse interactions', () => {
4296
4300
4297
4301
// We should not be able to focus the first option
4298
4302
await focus ( options [ 1 ] )
4299
- assertNoActiveComboboxOption ( )
4303
+ assertNotActiveComboboxOption ( options [ 1 ] )
4300
4304
} )
4301
4305
)
4302
4306
0 commit comments