1
1
import { useRef , useState } from 'react' ;
2
2
import { createFileRoute } from '@tanstack/react-router' ;
3
3
import { css } from '@linaria/core' ;
4
+ import clsx from 'clsx' ;
4
5
5
6
import { DataGrid } from '../../src' ;
6
7
import type { Column , DataGridHandle } from '../../src' ;
@@ -29,13 +30,23 @@ for (let i = 0; i < 200; i++) {
29
30
const flexClassname = css `
30
31
display : flex;
31
32
gap : 5px ;
33
+ align-items : center;
32
34
margin-block-end : 5px ;
35
+
36
+ > fieldset {
37
+ display : contents;
38
+ }
39
+ ` ;
40
+
41
+ const smoothClassname = css `
42
+ scroll-behavior : smooth;
33
43
` ;
34
44
35
45
function ScrollToCell ( ) {
36
46
const direction = useDirection ( ) ;
37
47
const [ idx , setIdx ] = useState < number | undefined > ( 10 ) ;
38
48
const [ rowIdx , setRowIdx ] = useState < number | undefined > ( 10 ) ;
49
+ const [ scrollBehavior , setScrollBehavior ] = useState < ScrollBehavior > ( 'auto' ) ;
39
50
const gridRef = useRef < DataGridHandle > ( null ) ;
40
51
41
52
function scrollToColumn ( ) {
@@ -77,6 +88,31 @@ function ScrollToCell() {
77
88
} }
78
89
/>
79
90
</ label >
91
+ < fieldset >
92
+ < legend > Scroll behavior</ legend >
93
+ < label >
94
+ Auto
95
+ < input
96
+ type = "radio"
97
+ name = "scroll-behavior"
98
+ checked = { scrollBehavior === 'auto' }
99
+ onChange = { ( ) => {
100
+ setScrollBehavior ( 'auto' ) ;
101
+ } }
102
+ />
103
+ </ label >
104
+ < label >
105
+ Smooth
106
+ < input
107
+ type = "radio"
108
+ name = "scroll-behavior"
109
+ checked = { scrollBehavior === 'smooth' }
110
+ onChange = { ( ) => {
111
+ setScrollBehavior ( 'smooth' ) ;
112
+ } }
113
+ />
114
+ </ label >
115
+ </ fieldset >
80
116
</ div >
81
117
< div className = { flexClassname } >
82
118
< button type = "button" onClick = { scrollToCell } >
@@ -93,7 +129,7 @@ function ScrollToCell() {
93
129
ref = { gridRef }
94
130
columns = { columns }
95
131
rows = { rows }
96
- className = " fill-grid"
132
+ className = { clsx ( ' fill-grid' , { [ smoothClassname ] : scrollBehavior === 'smooth' } ) }
97
133
direction = { direction }
98
134
/>
99
135
</ >
0 commit comments