Skip to content

Commit

Permalink
Optional focus prop
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Nov 4, 2024
1 parent 8b9cf23 commit 994b4e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@
"@rollup/plugin-terser": "0.4.4",
"@rollup/plugin-typescript": "12.1.1",
"@testing-library/react": "16.0.1",
"@types/node": "22.8.2",
"@types/node": "22.8.7",
"@types/react": "18.3.12",
"@types/react-dom": "18.3.1",
"@vitest/coverage-v8": "2.1.4",
"eslint": "9.13.0",
"eslint": "9.14.0",
"eslint-plugin-react": "7.37.2",
"http-server": "14.1.1",
"jsdom": "25.0.1",
"tslib": "2.8.0",
"tslib": "2.8.1",
"typescript": "5.6.3",
"typescript-eslint": "8.12.1",
"typescript-eslint": "8.13.0",
"vitest": "2.1.4"
},
"peerDependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/HighTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface TableProps {
cacheKey?: string // used to persist column widths
overscan?: number // number of rows to fetch outside of the viewport
padding?: number // number of padding rows to render outside of the viewport
focus?: boolean // focus table on mount (default true)
onDoubleClickCell?: (col: number, row: number) => void
onMouseDownCell?: (event: React.MouseEvent, col: number, row: number) => void
onError?: (error: Error) => void
Expand Down Expand Up @@ -90,6 +91,7 @@ export default function HighTable({
cacheKey,
overscan = 20,
padding = 20,
focus = true,
onDoubleClickCell,
onMouseDownCell,
onError = console.error,
Expand Down Expand Up @@ -126,7 +128,7 @@ export default function HighTable({

if (isNaN(start)) throw new Error('invalid start row ' + start)
if (isNaN(end)) throw new Error('invalid end row ' + end)
if (end - start > 1000) throw new Error('too many rows to fetch ' + (end - start))
if (end - start > 1000) throw new Error('attempted to render too many rows ' + (end - start) + ' table must be contained in a scrollable div')

const offsetTop = Math.max(0, start - padding) * rowHeight

Expand Down Expand Up @@ -235,8 +237,10 @@ export default function HighTable({

// focus table on mount so arrow keys work
useEffect(() => {
tableRef.current?.focus()
}, [])
if (focus) {
tableRef.current?.focus()
}
}, [focus])

// reset dataReady when data changes so that columns will auto-resize
useEffect(() => {
Expand Down

0 comments on commit 994b4e8

Please sign in to comment.