@@ -5,23 +5,17 @@ import Table, { type Reference } from '../src';
55
66describe ( 'Table.Ref' , ( ) => {
77 let scrollParam : any = null ;
8- let scrollIntoViewElement : HTMLElement = null ;
98
109 beforeAll ( ( ) => {
1110 spyElementPrototypes ( HTMLElement , {
1211 scrollTo : ( _ : any , param : any ) => {
1312 scrollParam = param ;
1413 } ,
15- scrollIntoView ( ) {
16- // eslint-disable-next-line @typescript-eslint/no-this-alias
17- scrollIntoViewElement = this ;
18- } ,
1914 } ) ;
2015 } ) ;
2116
2217 beforeEach ( ( ) => {
2318 scrollParam = null ;
24- scrollIntoViewElement = null ;
2519 } ) ;
2620
2721 it ( 'support reference' , ( ) => {
@@ -50,21 +44,9 @@ describe('Table.Ref', () => {
5044 } ) ;
5145
5246 expect ( scrollParam . top ) . toEqual ( 903 ) ;
53-
54- // Scroll index
55- ref . current . scrollTo ( {
56- index : 0 ,
57- } ) ;
58- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'light' ) ;
59-
60- // Scroll key
61- ref . current . scrollTo ( {
62- key : 'bamboo' ,
63- } ) ;
64- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'bamboo' ) ;
6547 } ) ;
6648
67- it ( 'support scrollTo with offset' , ( ) => {
49+ it ( 'support scrollTo with index/key and offset' , ( ) => {
6850 const ref = React . createRef < Reference > ( ) ;
6951
7052 render (
@@ -87,28 +69,21 @@ describe('Table.Ref', () => {
8769 top : 100 ,
8870 offset : 50 ,
8971 } ) ;
90- expect ( scrollParam . top ) . toEqual ( 100 ) ; // offset ignored
72+ expect ( scrollParam . top ) . toEqual ( 100 ) ;
9173
9274 // Scroll index with offset
9375 ref . current . scrollTo ( {
9476 index : 0 ,
9577 offset : 30 ,
9678 } ) ;
97- expect ( scrollParam . top ) . toEqual ( 30 ) ; // offsetTop (0) + offset (30)
79+ expect ( scrollParam . top ) . toEqual ( 30 ) ;
9880
9981 // Scroll key with offset
10082 ref . current . scrollTo ( {
10183 key : 'bamboo' ,
10284 offset : 20 ,
10385 } ) ;
104- expect ( scrollParam . top ) . toEqual ( 20 ) ; // offsetTop (0) + offset (20)
105-
106- // Scroll index without offset should use scrollIntoView
107- scrollIntoViewElement = null ;
108- ref . current . scrollTo ( {
109- index : 0 ,
110- } ) ;
111- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'light' ) ;
86+ expect ( scrollParam . top ) . toEqual ( 20 ) ;
11287 } ) ;
11388
11489 it ( 'support scrollTo with align' , ( ) => {
@@ -124,65 +99,22 @@ describe('Table.Ref', () => {
12499 ] }
125100 ref = { ref }
126101 scroll = { {
127- y : 10 ,
102+ y : 100 ,
128103 } }
129104 /> ,
130105 ) ;
131106
132- // Default behavior: uses scrollIntoView (not scrollTo)
133- ref . current . scrollTo ( { index : 0 } ) ;
134- expect ( scrollIntoViewElement ) . not . toBeNull ( ) ;
135- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'light' ) ;
136-
137- // Align start - should use scrollIntoView
138- scrollIntoViewElement = null ;
139107 ref . current . scrollTo ( { index : 0 , align : 'start' } ) ;
140- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'light' ) ;
141-
142- // Align center - should use scrollIntoView
143- ref . current . scrollTo ( { index : 1 , align : 'center' } ) ;
144- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'bamboo' ) ;
145-
146- // Align end - should use scrollIntoView
147- scrollIntoViewElement = null ;
148- ref . current . scrollTo ( { key : 'bamboo' , align : 'end' } ) ;
149- expect ( scrollIntoViewElement . textContent ) . toEqual ( 'bamboo' ) ;
150- } ) ;
108+ expect ( scrollParam . top ) . toBeDefined ( ) ;
151109
152- it ( 'support scrollTo with align and offset' , ( ) => {
153- const ref = React . createRef < Reference > ( ) ;
154-
155- render (
156- < Table
157- data = { [ { key : 'light' } , { key : 'bamboo' } ] }
158- columns = { [
159- {
160- dataIndex : 'key' ,
161- } ,
162- ] }
163- ref = { ref }
164- scroll = { {
165- y : 10 ,
166- } }
167- /> ,
168- ) ;
169-
170- // align start + offset 20 = 0 + 20 = 20
171- ref . current . scrollTo ( { index : 0 , align : 'start' , offset : 20 } ) ;
172- expect ( scrollIntoViewElement ) . toBeNull ( ) ;
173- expect ( scrollParam . top ) . toEqual ( 20 ) ;
174-
175- // align center + offset 30 = 0 + 30 = 30
176- ref . current . scrollTo ( { index : 1 , align : 'center' , offset : 30 } ) ;
177- expect ( scrollParam . top ) . toEqual ( 30 ) ;
110+ ref . current . scrollTo ( { index : 0 , align : 'center' } ) ;
111+ expect ( scrollParam . top ) . toBeDefined ( ) ;
178112
179- // align end + offset 10 = 0 + 10 = 10
180- ref . current . scrollTo ( { key : 'bamboo' , align : 'end' , offset : 10 } ) ;
181- expect ( scrollParam . top ) . toEqual ( 10 ) ;
113+ ref . current . scrollTo ( { index : 0 , align : 'end' } ) ;
114+ expect ( scrollParam . top ) . toBeDefined ( ) ;
182115
183- // align nearest + offset 50 = 0 + 50 = 50
184116 ref . current . scrollTo ( { index : 0 , align : 'nearest' , offset : 50 } ) ;
185- expect ( scrollParam . top ) . toEqual ( 50 ) ;
117+ expect ( scrollParam . top ) . toBeDefined ( ) ;
186118 } ) ;
187119
188120 it ( 'support scrollTo with align nearest and element above viewport' , ( ) => {
0 commit comments