File tree Expand file tree Collapse file tree 4 files changed +24
-2
lines changed
examples/src/pages/tests/table/props/active-row-index Expand file tree Collapse file tree 4 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ export default function KeyboardNavigationForRows() {
55
55
defaultActiveRowIndex = { 99 }
56
56
keyboardNavigation = "row"
57
57
domProps = { {
58
+ autoFocus : true ,
58
59
style : {
59
60
height : 800 ,
60
61
} ,
Original file line number Diff line number Diff line change @@ -165,6 +165,8 @@ export function HeadlessTable(
165
165
...domProps
166
166
} = props ;
167
167
168
+ const { autoFocus } = domProps ;
169
+
168
170
const domRef = useRef < HTMLDivElement > ( null ) ;
169
171
170
172
const [ scrollSize , setTotalScrollSize ] = useState ( {
@@ -183,6 +185,9 @@ export function HeadlessTable(
183
185
if ( ! node ) {
184
186
return ;
185
187
}
188
+ if ( autoFocus && document . activeElement !== node ) {
189
+ node . focus ( ) ;
190
+ }
186
191
const onResize = ( ) => {
187
192
// it's not enough to read the size from onResize
188
193
// since that doesn't account for scrollbar presence and size
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ function InfiniteTableBody<T>() {
173
173
activeCellIndex,
174
174
rowDetailRenderer,
175
175
showHoverRows,
176
+ domProps,
176
177
} = componentState ;
177
178
178
179
const LoadMaskCmp = components ?. LoadMask ?? LoadMask ;
@@ -243,11 +244,14 @@ function InfiniteTableBody<T>() {
243
244
computed,
244
245
} ) ;
245
246
247
+ const { autoFocus, tabIndex } = domProps ?? { } ;
248
+
246
249
return (
247
250
< InfiniteTableBodyContainer onContextMenu = { onContextMenu } >
248
251
< HeadlessTable
249
252
debugId = { debugId }
250
- tabIndex = { 0 }
253
+ tabIndex = { tabIndex ?? 0 }
254
+ autoFocus = { autoFocus ?? undefined }
251
255
activeRowIndex = {
252
256
componentState . ready && keyboardNavigation === 'row'
253
257
? activeRowIndex
@@ -336,7 +340,16 @@ export const InfiniteTableComponent = React.memo(
336
340
337
341
const licenseValid = useLicense ( licenseKey ) ;
338
342
339
- const domProps = useDOMProps < T > ( componentState . domProps ) ;
343
+ const {
344
+ // remove autoFocus and tabIndex from the domProps
345
+ // that will be spread on the root DOM element
346
+ // as they are meant for the scroller element
347
+ autoFocus : _ ,
348
+ tabIndex : __ ,
349
+ ...initialDOMProps
350
+ } = componentState . domProps ?? { } ;
351
+
352
+ const domProps = useDOMProps < T > ( initialDOMProps ) ;
340
353
341
354
React . useEffect ( ( ) => {
342
355
brain . setScrollStopDelay ( scrollStopDelay ) ;
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export interface VirtualScrollContainerProps {
22
22
23
23
scrollable ?: Scrollable ;
24
24
tabIndex ?: number ;
25
+ autoFocus ?: boolean ;
25
26
26
27
onContainerScroll ?: ( scrollPos : {
27
28
scrollTop : number ;
@@ -42,6 +43,7 @@ export const VirtualScrollContainer = React.forwardRef(
42
43
className,
43
44
tabIndex,
44
45
style,
46
+ autoFocus,
45
47
} = props ;
46
48
47
49
const domRef = ref ?? useRef < HTMLDivElement | null > ( null ) ;
@@ -54,6 +56,7 @@ export const VirtualScrollContainer = React.forwardRef(
54
56
< div
55
57
ref = { domRef }
56
58
style = { style }
59
+ autoFocus = { autoFocus }
57
60
tabIndex = { tabIndex }
58
61
className = { join (
59
62
className ,
You can’t perform that action at this time.
0 commit comments