Skip to content

Commit 95880b1

Browse files
committed
Reset data-table paging when panel collapses
Reset the visible row count to the sample size whenever the data-summary panel collapses to avoid re-rendering large row sets on reopen. Added useEffect hooks in AccessibleDataTable and NetworkAccessibleDataTable to reset visibleCount when isExpanded becomes false, and removed redundant setVisibleCount calls from dismiss. Added a test to verify paging resets after collapsing and reopened. Also fixed a docs comment ("sales" -> "revenue").
1 parent c6b9c39 commit 95880b1

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

docs/src/pages/features/AccessibilityPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ export default function AccessibilityPage() {
251251
</ChartContainer>
252252
253253
// The summary shows:
254-
// "72 data points. month: 1 to 12, mean 6.5. sales: 12000 to 27000, mean 18500."
254+
// "72 data points. month: 1 to 12, mean 6.5. revenue: 12000 to 27000, mean 18500."
255255
// + a sample table of the real data values, pageable to all 72 rows
256256
257257
// For screen readers, the summary is always available via a hidden button

src/components/stream/AccessibleDataTable.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ describe("AccessibleDataTable — focus & pagination", () => {
211211
// No further "Show more" once everything is shown.
212212
expect(screen.queryByRole("button", { name: /show .* more/i })).toBeNull()
213213
})
214+
215+
it("resets paging back to the initial sample after the panel collapses", () => {
216+
render(<AccessibleDataTable tableId="t4" chartType="line chart" scene={lineScene(40)} />)
217+
fireEvent.click(screen.getByRole("button", { name: /view data summary/i }))
218+
fireEvent.click(screen.getByRole("button", { name: /show .* more rows/i }))
219+
expect(screen.getAllByRole("row")).toHaveLength(30 + 1)
220+
221+
// Collapse, then reopen — must be back to the bounded 5-row sample, not 30.
222+
fireEvent.click(screen.getByRole("button", { name: /close data summary/i }))
223+
fireEvent.click(screen.getByRole("button", { name: /view data summary/i }))
224+
expect(screen.getAllByRole("row")).toHaveLength(5 + 1)
225+
})
214226
})
215227

216228
// ── extractAllRows logic ────────────────────────────────────────────────

src/components/stream/AccessibleDataTable.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,13 @@ export function AccessibleDataTable({ scene, chartType, tableId, chartTitle }: A
413413
const containerRef = React.useRef<HTMLDivElement>(null)
414414
const regionLabel = chartTitle ? `Data summary for ${chartTitle}` : tableId ? `Data summary for ${chartType} ${tableId}` : `Data summary for ${chartType}`
415415

416+
// Reset paging whenever the panel collapses — via the close button, a blur in
417+
// sr-only mode, or ChartContainer toggling visibility off — so reopening never
418+
// re-renders the full (potentially huge) row set at once.
419+
React.useEffect(() => {
420+
if (!isExpanded) setVisibleCount(SAMPLE_SIZE)
421+
}, [isExpanded])
422+
416423
// Expand only when focus lands on the region container itself (the skip-link
417424
// path programmatically focuses it). Focus bubbling up from the inner trigger
418425
// button must NOT auto-expand — otherwise merely tabbing onto the button
@@ -463,7 +470,7 @@ export function AccessibleDataTable({ scene, chartType, tableId, chartTitle }: A
463470
const dismiss = () => {
464471
if (visible && dataSummary) dataSummary.setVisible(false)
465472
setSrExpanded(false)
466-
setVisibleCount(SAMPLE_SIZE)
473+
// visibleCount resets via the collapse effect above.
467474
}
468475

469476
const showMore = () => setVisibleCount((c) => c + PAGE_SIZE)
@@ -526,6 +533,12 @@ export function NetworkAccessibleDataTable({ nodes, edges, chartType, tableId, c
526533
const regionLabel = chartTitle ? `Data summary for ${chartTitle}` : tableId ? `Data summary for ${chartType} ${tableId}` : `Data summary for ${chartType}`
527534
const containerRef = React.useRef<HTMLDivElement>(null)
528535

536+
// Reset paging on any collapse path (close button, blur, ChartContainer
537+
// toggle) so reopening never re-renders the full node set at once.
538+
React.useEffect(() => {
539+
if (!isExpanded) setVisibleCount(SAMPLE_SIZE)
540+
}, [isExpanded])
541+
529542
// Only the skip-link path (which focuses the region container itself) auto-
530543
// expands; focus bubbling from the inner trigger button must not. See the
531544
// matching note in AccessibleDataTable.
@@ -629,7 +642,7 @@ export function NetworkAccessibleDataTable({ nodes, edges, chartType, tableId, c
629642
const dismiss = () => {
630643
if (visible && dataSummary) dataSummary.setVisible(false)
631644
setSrExpanded(false)
632-
setVisibleCount(SAMPLE_SIZE)
645+
// visibleCount resets via the collapse effect above.
633646
}
634647

635648
const showMore = () => setVisibleCount((c) => c + PAGE_SIZE)

0 commit comments

Comments
 (0)