@@ -6,6 +6,7 @@ import { addressOptions, addressOptionsForUneven, optionsForActiveMenuItems } fr
66import { mount } from './enzyme' ;
77import { toRawValues } from '../src/utils/commonUtil' ;
88import { fireEvent , render } from '@testing-library/react' ;
9+ import KeyCode from '@rc-component/util/lib/KeyCode' ;
910
1011describe ( 'Cascader.Basic' , ( ) => {
1112 let selectedValue : any ;
@@ -995,6 +996,7 @@ describe('Cascader.Basic', () => {
995996 wrapper . find ( `li[data-path-key]` ) . at ( 0 ) . simulate ( 'click' ) ;
996997 wrapper . find ( `li[data-path-key]` ) . at ( 1 ) . simulate ( 'click' ) ;
997998 } ) ;
999+
9981000 it ( 'hover + search' , ( ) => {
9991001 let getOffesetTopTimes = 0 ;
10001002 const spyElement = spyElementPrototypes ( HTMLElement , {
@@ -1074,6 +1076,34 @@ describe('Cascader.Basic', () => {
10741076
10751077 spyElement . mockRestore ( ) ;
10761078 } ) ;
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+ } ) ;
10771107 } ) ;
10781108
10791109 it ( 'not crash when value type is not array' , ( ) => {
0 commit comments