File tree Expand file tree Collapse file tree 4 files changed +39
-15
lines changed
components/AnalyticalTable Expand file tree Collapse file tree 4 files changed +39
-15
lines changed Original file line number Diff line number Diff line change 11import { createPassThroughPropsTest , mountThemedComponent } from '@shared/tests/utils' ;
22import { AnalyticalTable } from '@ui5/webcomponents-react/lib/AnalyticalTable' ;
33import { TableSelectionMode } from '@ui5/webcomponents-react/lib/TableSelectionMode' ;
4- import React from 'react' ;
4+ import { AnalyticalTableScrollMode } from '@ui5/webcomponents-react/lib/AnalyticalTableScrollMode' ;
5+ import React , { useRef } from 'react' ;
56
67const columns = [
78 {
@@ -277,5 +278,25 @@ describe('AnalyticalTable', () => {
277278 expect ( wrapper . render ( ) ) . toMatchSnapshot ( ) ;
278279 } ) ;
279280
281+ test ( 'Check for scrollTo and scrollToItem functions' , ( ) => {
282+ let tableRef ;
283+ const UsingTable = ( props ) => {
284+ tableRef = useRef ( null ) ;
285+ return < AnalyticalTable ref = { tableRef } title = "Table Title" data = { data } columns = { columns } /> ;
286+ } ;
287+
288+ mountThemedComponent ( < UsingTable /> ) ;
289+
290+ // Check existence + type
291+ expect ( typeof tableRef . current . scrollTo ) . toBe ( 'function' ) ;
292+ expect ( typeof tableRef . current . scrollToItem ) . toBe ( 'function' ) ;
293+
294+ // call functions
295+ const tableInnerRef = tableRef . current . querySelector ( "div[class^='AnalyticalTable--table'] > div > div" ) ;
296+ tableRef . current . scrollToItem ( 2 , AnalyticalTableScrollMode . end ) ;
297+ tableRef . current . scrollTo ( 2 ) ;
298+ expect ( tableInnerRef . scrollTop ) . toBe ( 2 ) ;
299+ } ) ;
300+
280301 createPassThroughPropsTest ( AnalyticalTable ) ;
281302} ) ;
Original file line number Diff line number Diff line change @@ -5,19 +5,21 @@ import { AnalyticalTableDomRef } from '../../../interfaces/AnalyticalTableDomRef
55export const useTableScrollHandles = ( ref ) => {
66 const analyticalTableRef : RefObject < AnalyticalTableDomRef > = useConsolidatedRef ( ref ) ;
77 const reactWindowRef = useRef ( null ) ;
8- // @ts -ignore
9- useImperativeHandle ( analyticalTableRef , ( ) => ( {
10- scrollTo : ( ...args ) => {
11- if ( reactWindowRef . current ) {
12- reactWindowRef . current . scrollTo ( ...args ) ;
13- }
14- } ,
15- scrollToItem : ( ...args ) => {
16- if ( reactWindowRef . current ) {
17- reactWindowRef . current . scrollToItem ( ...args ) ;
8+
9+ if ( analyticalTableRef . current ) {
10+ Object . assign ( analyticalTableRef . current , {
11+ scrollTo : ( ...args ) => {
12+ if ( reactWindowRef . current ) {
13+ reactWindowRef . current . scrollTo ( ...args ) ;
14+ }
15+ } ,
16+ scrollToItem : ( ...args ) => {
17+ if ( reactWindowRef . current ) {
18+ reactWindowRef . current . scrollToItem ( ...args ) ;
19+ }
1820 }
19- }
20- } ) ) ;
21+ } ) ;
22+ }
2123
2224 return [ analyticalTableRef , reactWindowRef ] ;
2325} ;
Original file line number Diff line number Diff line change @@ -114,7 +114,7 @@ export interface TableProps extends CommonProps {
114114 onRowExpandChange ?: ( e ?: Event ) => any ;
115115 onColumnsReordered ?: ( e ?: Event ) => void ;
116116 /**
117- * additional options which will be passed to [react-table´s useTable hook](https://github.com/tannerlinsley/react-table/blob/master/docs/api.md#table-options)
117+ * additional options which will be passed to [react-table´s useTable hook](https://github.com/tannerlinsley/react-table/blob/master/docs/api/useTable .md#table-options)
118118 */
119119 reactTableOptions ?: object ;
120120 tableHooks ?: PluginHook < any > [ ] ;
Original file line number Diff line number Diff line change 11import { AnalyticalTableScrollMode } from '@ui5/webcomponents-react/lib/AnalyticalTableScrollMode' ;
22
3- // also makes use of scrollTo which is already defined somewhere in HTMLDivElement
3+ //@ts -ignore
44export interface AnalyticalTableDomRef extends HTMLDivElement {
55 scrollToItem : ( index : number , align ?: AnalyticalTableScrollMode ) => void ;
6+ scrollTo : ( scrollOffset : number ) => void ; //overrides native scrollTo function
67}
You can’t perform that action at this time.
0 commit comments