@@ -6,6 +6,7 @@ import { addressOptions, addressOptionsForUneven, optionsForActiveMenuItems } fr
6
6
import { mount } from './enzyme' ;
7
7
import { toRawValues } from '../src/utils/commonUtil' ;
8
8
import { fireEvent , render } from '@testing-library/react' ;
9
+ import KeyCode from '@rc-component/util/lib/KeyCode' ;
9
10
10
11
describe ( 'Cascader.Basic' , ( ) => {
11
12
let selectedValue : any ;
@@ -995,6 +996,7 @@ describe('Cascader.Basic', () => {
995
996
wrapper . find ( `li[data-path-key]` ) . at ( 0 ) . simulate ( 'click' ) ;
996
997
wrapper . find ( `li[data-path-key]` ) . at ( 1 ) . simulate ( 'click' ) ;
997
998
} ) ;
999
+
998
1000
it ( 'hover + search' , ( ) => {
999
1001
let getOffesetTopTimes = 0 ;
1000
1002
const spyElement = spyElementPrototypes ( HTMLElement , {
@@ -1074,6 +1076,34 @@ describe('Cascader.Basic', () => {
1074
1076
1075
1077
spyElement . mockRestore ( ) ;
1076
1078
} ) ;
1079
+
1080
+ it ( 'should scroll into view when navigating with keyboard' , ( ) => {
1081
+ const { container } = render (
1082
+ < Cascader
1083
+ options = { Array . from ( { length : 20 } ) . map ( ( _ , index ) => ( {
1084
+ value : `item-${ index } ` ,
1085
+ label : `item-${ index } ` ,
1086
+ } ) ) }
1087
+ open
1088
+ /> ,
1089
+ ) ;
1090
+
1091
+ const input = container . querySelector ( 'input' ) ! ;
1092
+ fireEvent . focus ( input ) ;
1093
+
1094
+ fireEvent . keyDown ( input , { key : 'ArrowDown' , keyCode : KeyCode . DOWN } ) ;
1095
+
1096
+ const targetElement = container . querySelector ( '.rc-cascader-menu-item-active' ) ! ;
1097
+
1098
+ const scrollSpy = jest . spyOn ( targetElement , 'scrollIntoView' ) . mockImplementation ( ( ) => null ) ;
1099
+
1100
+ expect ( scrollSpy ) . toHaveBeenCalledWith ( {
1101
+ block : 'nearest' ,
1102
+ inline : 'nearest' ,
1103
+ } ) ;
1104
+
1105
+ scrollSpy . mockReset ( ) ;
1106
+ } ) ;
1077
1107
} ) ;
1078
1108
1079
1109
it ( 'not crash when value type is not array' , ( ) => {
0 commit comments