From 51d7b4a60d18d989eb8792f6bb66d5867af07d31 Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Mon, 14 Sep 2026 17:53:14 +0000 Subject: [PATCH 1/8] fix: point pinned scrollbar aria-controls at the container's real id The thumb's aria-controls was hardcoded to this mount's useId value, but the sync effect only stamps that id onto the scroll container when the container has none. When the host app supplies its own id, or when the component remounts onto a container a previous mount already labelled, aria-controls names an element that does not exist and assistive tech cannot resolve the scrollbar's target. Track the id actually present on the element instead. --- src/__tests__/pinning.test.tsx | 73 ++++++++++++++++++++++++++++++ src/components/PinnedScrollbar.tsx | 10 +++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index 0acd2324..1f85ee1e 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -195,4 +195,77 @@ describe('PinnedScrollbar', () => { expect(ref.current!.scrollLeft).toBeGreaterThanOrEqual(0); } }); + + // Control: the container has no id of its own, so the effect stamps it with + // this mount's useId and aria-controls matches either way. Green before and + // after the fix — it pins the untouched offset-0 case so the fix can't be + // read as changing the ordinary first-mount path. + test('aria-controls resolves to the scroll container it labelled (control)', async () => { + const ref = makeScrollRef(1000, 400); + document.body.appendChild(ref.current!); + const { container, unmount } = renderWithTheme(); + + await act(async () => { + ref.current!.dispatchEvent(new Event('scroll')); + }); + + const thumb = container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + const controls = thumb.getAttribute('aria-controls'); + expect(controls).toBe(ref.current!.id); + expect(document.getElementById(controls!)).toBe(ref.current); + + unmount(); + ref.current!.remove(); + }); + + // A dangling aria-controls is invisible in a rendered-DOM assertion — it only + // shows up when you resolve the id, which is what assistive tech does. + test('aria-controls points at a host-supplied container id instead of a fresh one', async () => { + const ref = makeScrollRef(1000, 400); + ref.current!.id = 'host-app-scroll-container'; + document.body.appendChild(ref.current!); + const { container, unmount } = renderWithTheme(); + + await act(async () => { + ref.current!.dispatchEvent(new Event('scroll')); + }); + + const thumb = container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + // The container already had an id, so the effect leaves it alone — the thumb + // must follow it rather than pointing at its own unused useId value. + expect(ref.current!.id).toBe('host-app-scroll-container'); + expect(thumb.getAttribute('aria-controls')).toBe('host-app-scroll-container'); + expect(document.getElementById(thumb.getAttribute('aria-controls')!)).toBe(ref.current); + + unmount(); + ref.current!.remove(); + }); + + test('aria-controls survives a remount onto the same container', async () => { + const ref = makeScrollRef(1000, 400); + document.body.appendChild(ref.current!); + + // First mount stamps the container with its useId value. + const first = renderWithTheme(); + await act(async () => { + ref.current!.dispatchEvent(new Event('scroll')); + }); + const stampedId = ref.current!.id; + first.unmount(); + + // Unmounting doesn't clear the id, and the remount gets a *different* useId. + // Unpinning then re-pinning a column does exactly this in DataTable. + const second = renderWithTheme(); + await act(async () => { + ref.current!.dispatchEvent(new Event('scroll')); + }); + + const thumb = second.container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + expect(ref.current!.id).toBe(stampedId); + expect(thumb.getAttribute('aria-controls')).toBe(stampedId); + expect(document.getElementById(thumb.getAttribute('aria-controls')!)).toBe(ref.current); + + second.unmount(); + ref.current!.remove(); + }); }); diff --git a/src/components/PinnedScrollbar.tsx b/src/components/PinnedScrollbar.tsx index 6f61b393..b1d89c87 100644 --- a/src/components/PinnedScrollbar.tsx +++ b/src/components/PinnedScrollbar.tsx @@ -13,6 +13,9 @@ export default function PinnedScrollbar({ rightInset, }: PinnedScrollbarProps): JSX.Element | null { const scrollContainerId = React.useId(); + // The id the thumb points at. Only equals scrollContainerId when this + // component is the one that labelled the container — see the sync effect. + const [controlsId, setControlsId] = React.useState(scrollContainerId); const trackRef = React.useRef(null); const thumbRef = React.useRef(null); const [thumbWidth, setThumbWidth] = React.useState(0); @@ -62,6 +65,11 @@ export default function PinnedScrollbar({ if (!el.id) { el.id = scrollContainerId; } + // The container keeps whatever id it already had — a host-supplied one, or + // one left behind by a previous mount (useId hands out a fresh value each + // time). Point aria-controls at the id that is actually on the element, or + // it dangles and assistive tech can't resolve the scrollbar's target. + setControlsId(el.id); el.addEventListener('scroll', update, { passive: true }); const ro = new ResizeObserver(update); ro.observe(el); @@ -191,7 +199,7 @@ export default function PinnedScrollbar({ ref={thumbRef} role="scrollbar" tabIndex={0} - aria-controls={scrollContainerId} + aria-controls={controlsId} aria-orientation="horizontal" aria-valuenow={scrollPercent} aria-valuemin={0} From c90a44c5f624264476ccc5bc8e7d5e7544f85598 Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Mon, 14 Sep 2026 18:55:52 +0000 Subject: [PATCH 2/8] test: cover pinned scrollbar aria-controls across an unpin/re-pin cycle The unit test drives the remount directly against PinnedScrollbar. Exercise the same path through DataTable's public API, where unpinning every column drops hasPinnedColumns and re-pinning mounts a fresh scrollbar over the wrapper the previous mount already labelled. --- src/__tests__/pinning.test.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index 1f85ee1e..a988b49f 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -101,6 +101,32 @@ describe('DataTable column pinning', () => { expect(offsets).toContain(0); expect(offsets.some(v => v > 0)).toBe(true); }); + + test('pinned scrollbar aria-controls still resolves after a column is unpinned and re-pinned', async () => { + const unpinnedCols: TableColumn[] = columns.map(c => ({ ...c, pinned: undefined })); + const { container, rerender } = render(); + + const wrapper = container.querySelector('.rdt_responsiveWrapper') as HTMLElement; + Object.defineProperty(wrapper, 'scrollWidth', { configurable: true, get: () => 1000 }); + Object.defineProperty(wrapper, 'clientWidth', { configurable: true, get: () => 400 }); + await act(async () => { + wrapper.dispatchEvent(new Event('scroll')); + }); + + // Unpinning every column drops hasPinnedColumns, which unmounts the + // scrollbar; re-pinning mounts a fresh one with a new useId, while the + // wrapper keeps the id the first mount stamped on it. + rerender(); + rerender(); + await act(async () => { + wrapper.dispatchEvent(new Event('scroll')); + }); + + const thumb = container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + const controls = thumb.getAttribute('aria-controls'); + expect(controls).toBe(wrapper.id); + expect(document.getElementById(controls!)).toBe(wrapper); + }); }); // ── PinnedScrollbar ────────────────────────────────────────────────────────── From 77313f74f999f8e2be78247d8897980e712b17be Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Mon, 14 Sep 2026 20:26:32 +0000 Subject: [PATCH 3/8] test: cover pinned scrollbar aria-controls container changes --- src/__tests__/pinning.test.tsx | 90 ++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index a988b49f..290891d6 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -294,4 +294,94 @@ describe('PinnedScrollbar', () => { second.unmount(); ref.current!.remove(); }); + + // The effect keys on the *ref object*, so pointing the component at a + // different container mid-life re-runs it. The container swapped in already + // has an id, so nothing is stamped and aria-controls has to follow it. + test('aria-controls re-points when the scroll container is swapped for another one', async () => { + const first = makeScrollRef(1000, 400).current!; + const second = makeScrollRef(1000, 400).current!; + second.id = 'second-scroll-container'; + document.body.append(first, second); + + let swap!: (el: HTMLDivElement) => void; + function SwapHarness({ initial }: { initial: HTMLDivElement }): JSX.Element { + const [target, setTarget] = React.useState(initial); + swap = setTarget; + const ref = React.useMemo(() => ({ current: target }) as React.RefObject, [target]); + return ; + } + + const { container, unmount } = renderWithTheme(); + await act(async () => { + first.dispatchEvent(new Event('scroll')); + }); + await act(async () => { + swap(second); + }); + + const thumb = container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + const controls = thumb.getAttribute('aria-controls'); + expect(controls).toBe('second-scroll-container'); + expect(document.getElementById(controls!)).toBe(second); + + unmount(); + first.remove(); + second.remove(); + }); + + // Reverse of the host-supplied-id case: the stamp happens first and the host + // takes the id over afterwards, so the remount sees an id it did not write. + test('aria-controls follows an id the host assigns after the first mount stamped one', async () => { + const ref = makeScrollRef(1000, 400); + document.body.appendChild(ref.current!); + + const first = renderWithTheme(); + await act(async () => { + ref.current!.dispatchEvent(new Event('scroll')); + }); + first.unmount(); + + ref.current!.id = 'host-took-over-later'; + const second = renderWithTheme(); + await act(async () => { + ref.current!.dispatchEvent(new Event('scroll')); + }); + + const thumb = second.container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + expect(thumb.getAttribute('aria-controls')).toBe('host-took-over-later'); + expect(document.getElementById(thumb.getAttribute('aria-controls')!)).toBe(ref.current); + + second.unmount(); + ref.current!.remove(); + }); + + // Control: two scrollbars on the page at once, each on its own container. + // Green before and after — the id each thumb points at is per-instance state, + // and this pins that the two never share one. + test('two concurrent scrollbars each control their own container (control)', async () => { + const a = makeScrollRef(1000, 400); + const b = makeScrollRef(1000, 400); + document.body.append(a.current!, b.current!); + + const firstRender = renderWithTheme(); + const secondRender = renderWithTheme(); + await act(async () => { + a.current!.dispatchEvent(new Event('scroll')); + b.current!.dispatchEvent(new Event('scroll')); + }); + + const thumbA = firstRender.container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + const thumbB = secondRender.container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; + const controlsA = thumbA.getAttribute('aria-controls'); + const controlsB = thumbB.getAttribute('aria-controls'); + expect(controlsA).not.toBe(controlsB); + expect(document.getElementById(controlsA!)).toBe(a.current); + expect(document.getElementById(controlsB!)).toBe(b.current); + + firstRender.unmount(); + secondRender.unmount(); + a.current!.remove(); + b.current!.remove(); + }); }); From 5c04a2463667a4d9872382be0a4f677c01c90d65 Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Mon, 14 Sep 2026 21:34:57 +0000 Subject: [PATCH 4/8] test: pin that an empty scroll ref emits no aria-controls at all The sync effect returns at `if (!el)` before it can stamp an id or set controlsId, so no thumb is rendered and no control reference is emitted. Green on both source arms - it pins the early-return row of the boundary ledger, which had no coverage of its own. --- src/__tests__/pinning.test.tsx | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index 290891d6..79c53b85 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -384,4 +384,22 @@ describe('PinnedScrollbar', () => { a.current!.remove(); b.current!.remove(); }); + + // Control: the effect bails at `if (!el) return` before it can stamp an id or + // call setControlsId, and `visible` never flips, so no thumb — and no + // aria-controls — is emitted at all. Green before and after the fix; it pins + // that the new state doesn't leak an attribute onto a scrollbar that the + // early return means was never rendered. + test('emits no thumb and no aria-controls when the scroll ref is empty (control)', async () => { + const ref = { current: null } as React.RefObject; + const { container, unmount } = renderWithTheme(); + + await act(async () => {}); + + expect(container.querySelector('.rdt_pinnedScrollbarTrack')).toBeNull(); + expect(container.querySelector('.rdt_pinnedScrollbarThumb')).toBeNull(); + expect(container.querySelector('[aria-controls]')).toBeNull(); + + unmount(); + }); }); From 0960f7774cf7f8ac051037ee8ea62425c06b9efd Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Thu, 17 Sep 2026 20:52:28 -0400 Subject: [PATCH 5/8] test: plain control-test comments, no em dashes, changelog entry Review feedback: the two control tests' comments now say only what each test pins and that it is green before and after the fix; every em dash this change introduced is gone; and the fix has a CHANGELOG entry under 8.10.0 / Bug fixes. --- CHANGELOG.md | 1 + src/__tests__/pinning.test.tsx | 19 ++++++++----------- src/components/PinnedScrollbar.tsx | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3aad930..dfb0ffdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ These are accessibility fixes, but they change the rendered markup, so tests tha - The column filter button now reports `aria-expanded` and `aria-haspopup="dialog"` instead of `aria-pressed`, which described it as a toggle rather than something that opens a panel. → [Filtering](/docs/filtering) ### Bug fixes +- **Pinned scrollbar** now sets `aria-controls` to the scroll container's real id. When the container already carried an id, or was labelled again after an unpin and re-pin, the thumb kept pointing at a generated id no element had, so assistive technology could not resolve what the scrollbar controlled. - Set filter checkboxes now use the table's own checkbox styling instead of the browser's native control, so they match the row selection checkboxes and follow the theme. → [Filtering](/docs/filtering) - Keyboard focus in the context menu is now distinguishable from mouse hover. Both painted the same background, so arrowing through the menu while the pointer rested on another item highlighted two items at once. → [Context menu](/docs/context-menu) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index 79c53b85..377af031 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -222,10 +222,8 @@ describe('PinnedScrollbar', () => { } }); - // Control: the container has no id of its own, so the effect stamps it with - // this mount's useId and aria-controls matches either way. Green before and - // after the fix — it pins the untouched offset-0 case so the fix can't be - // read as changing the ordinary first-mount path. + // Control, green before and after the fix: with no host id the effect labels + // the container itself, so aria-controls matches on an ordinary first mount. test('aria-controls resolves to the scroll container it labelled (control)', async () => { const ref = makeScrollRef(1000, 400); document.body.appendChild(ref.current!); @@ -244,7 +242,7 @@ describe('PinnedScrollbar', () => { ref.current!.remove(); }); - // A dangling aria-controls is invisible in a rendered-DOM assertion — it only + // A dangling aria-controls is invisible in a rendered-DOM assertion. It only // shows up when you resolve the id, which is what assistive tech does. test('aria-controls points at a host-supplied container id instead of a fresh one', async () => { const ref = makeScrollRef(1000, 400); @@ -257,7 +255,7 @@ describe('PinnedScrollbar', () => { }); const thumb = container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; - // The container already had an id, so the effect leaves it alone — the thumb + // The container already had an id, so the effect leaves it alone, and the thumb // must follow it rather than pointing at its own unused useId value. expect(ref.current!.id).toBe('host-app-scroll-container'); expect(thumb.getAttribute('aria-controls')).toBe('host-app-scroll-container'); @@ -356,9 +354,8 @@ describe('PinnedScrollbar', () => { ref.current!.remove(); }); - // Control: two scrollbars on the page at once, each on its own container. - // Green before and after — the id each thumb points at is per-instance state, - // and this pins that the two never share one. + // Control, green before and after the fix: two scrollbars on one page each + // point at their own container. test('two concurrent scrollbars each control their own container (control)', async () => { const a = makeScrollRef(1000, 400); const b = makeScrollRef(1000, 400); @@ -386,8 +383,8 @@ describe('PinnedScrollbar', () => { }); // Control: the effect bails at `if (!el) return` before it can stamp an id or - // call setControlsId, and `visible` never flips, so no thumb — and no - // aria-controls — is emitted at all. Green before and after the fix; it pins + // call setControlsId, and `visible` never flips, so no thumb, and no + // aria-controls, is emitted at all. Green before and after the fix; it pins // that the new state doesn't leak an attribute onto a scrollbar that the // early return means was never rendered. test('emits no thumb and no aria-controls when the scroll ref is empty (control)', async () => { diff --git a/src/components/PinnedScrollbar.tsx b/src/components/PinnedScrollbar.tsx index b1d89c87..d01aa59f 100644 --- a/src/components/PinnedScrollbar.tsx +++ b/src/components/PinnedScrollbar.tsx @@ -14,7 +14,7 @@ export default function PinnedScrollbar({ }: PinnedScrollbarProps): JSX.Element | null { const scrollContainerId = React.useId(); // The id the thumb points at. Only equals scrollContainerId when this - // component is the one that labelled the container — see the sync effect. + // component is the one that labelled the container. See the sync effect. const [controlsId, setControlsId] = React.useState(scrollContainerId); const trackRef = React.useRef(null); const thumbRef = React.useRef(null); @@ -65,7 +65,7 @@ export default function PinnedScrollbar({ if (!el.id) { el.id = scrollContainerId; } - // The container keeps whatever id it already had — a host-supplied one, or + // The container keeps whatever id it already had, a host-supplied one or // one left behind by a previous mount (useId hands out a fresh value each // time). Point aria-controls at the id that is actually on the element, or // it dangles and assistive tech can't resolve the scrollbar's target. From 7744522da87eaf28bf790393e2f4ec82d17b5fd6 Mon Sep 17 00:00:00 2001 From: askalf Date: Fri, 18 Sep 2026 08:09:52 -0400 Subject: [PATCH 6/8] test: remove appended containers in afterEach and state the invariants Containers the PinnedScrollbar tests append to document.body are now removed in afterEach rather than at the end of each test, so a failed assertion cannot leave them behind for the next test. The comments say what each case pins; the empty-ref case is synchronous; the changelog bullet sits under its heading with the blank line where it was. --- CHANGELOG.md | 2 +- src/__tests__/pinning.test.tsx | 65 ++++++++++++------------------ src/components/PinnedScrollbar.tsx | 9 ++--- 3 files changed, 30 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfb0ffdd..804563cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,8 +40,8 @@ These are accessibility fixes, but they change the rendered markup, so tests tha - The column filter button now reports `aria-expanded` and `aria-haspopup="dialog"` instead of `aria-pressed`, which described it as a toggle rather than something that opens a panel. → [Filtering](/docs/filtering) ### Bug fixes -- **Pinned scrollbar** now sets `aria-controls` to the scroll container's real id. When the container already carried an id, or was labelled again after an unpin and re-pin, the thumb kept pointing at a generated id no element had, so assistive technology could not resolve what the scrollbar controlled. +- **Pinned scrollbar** now sets `aria-controls` to the scroll container's real id. When the container already carried an id, or was labelled again after an unpin and re-pin, the thumb kept pointing at a generated id no element had, so assistive technology could not resolve what the scrollbar controlled. - Set filter checkboxes now use the table's own checkbox styling instead of the browser's native control, so they match the row selection checkboxes and follow the theme. → [Filtering](/docs/filtering) - Keyboard focus in the context menu is now distinguishable from mouse hover. Both painted the same background, so arrowing through the menu while the pointer rested on another item highlighted two items at once. → [Context menu](/docs/context-menu) - Checkboxes now show a focus ring when tabbed to. The styled checkbox hides the real input and draws its own box, which had no focus style, so keyboard users tabbing through row selection or a set filter checklist could not see where they were. → [Row selection](/docs/selection) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index 377af031..2e3f1303 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -139,6 +139,16 @@ function makeScrollRef(scrollWidth = 1000, clientWidth = 400): React.RefObject { + const attached: HTMLElement[] = []; + const attach = (el: HTMLElement): HTMLElement => { + document.body.appendChild(el); + attached.push(el); + return el; + }; + afterEach(() => { + for (const el of attached.splice(0)) el.remove(); + }); + test('renders null before ResizeObserver fires (no overflow detected yet)', () => { const ref = makeScrollRef(400, 400); // no overflow const { container } = renderWithTheme(); @@ -222,11 +232,10 @@ describe('PinnedScrollbar', () => { } }); - // Control, green before and after the fix: with no host id the effect labels - // the container itself, so aria-controls matches on an ordinary first mount. - test('aria-controls resolves to the scroll container it labelled (control)', async () => { + // With no host id the effect labels the container itself. + test('aria-controls resolves to the scroll container it labelled', async () => { const ref = makeScrollRef(1000, 400); - document.body.appendChild(ref.current!); + attach(ref.current!); const { container, unmount } = renderWithTheme(); await act(async () => { @@ -239,15 +248,12 @@ describe('PinnedScrollbar', () => { expect(document.getElementById(controls!)).toBe(ref.current); unmount(); - ref.current!.remove(); }); - // A dangling aria-controls is invisible in a rendered-DOM assertion. It only - // shows up when you resolve the id, which is what assistive tech does. test('aria-controls points at a host-supplied container id instead of a fresh one', async () => { const ref = makeScrollRef(1000, 400); ref.current!.id = 'host-app-scroll-container'; - document.body.appendChild(ref.current!); + attach(ref.current!); const { container, unmount } = renderWithTheme(); await act(async () => { @@ -255,19 +261,16 @@ describe('PinnedScrollbar', () => { }); const thumb = container.querySelector('.rdt_pinnedScrollbarThumb') as HTMLElement; - // The container already had an id, so the effect leaves it alone, and the thumb - // must follow it rather than pointing at its own unused useId value. expect(ref.current!.id).toBe('host-app-scroll-container'); expect(thumb.getAttribute('aria-controls')).toBe('host-app-scroll-container'); expect(document.getElementById(thumb.getAttribute('aria-controls')!)).toBe(ref.current); unmount(); - ref.current!.remove(); }); test('aria-controls survives a remount onto the same container', async () => { const ref = makeScrollRef(1000, 400); - document.body.appendChild(ref.current!); + attach(ref.current!); // First mount stamps the container with its useId value. const first = renderWithTheme(); @@ -290,17 +293,14 @@ describe('PinnedScrollbar', () => { expect(document.getElementById(thumb.getAttribute('aria-controls')!)).toBe(ref.current); second.unmount(); - ref.current!.remove(); }); - // The effect keys on the *ref object*, so pointing the component at a - // different container mid-life re-runs it. The container swapped in already - // has an id, so nothing is stamped and aria-controls has to follow it. + // The effect re-runs when the ref object changes, and the container swapped + // in keeps its own id. test('aria-controls re-points when the scroll container is swapped for another one', async () => { - const first = makeScrollRef(1000, 400).current!; - const second = makeScrollRef(1000, 400).current!; + const first = attach(makeScrollRef(1000, 400).current!); + const second = attach(makeScrollRef(1000, 400).current!); second.id = 'second-scroll-container'; - document.body.append(first, second); let swap!: (el: HTMLDivElement) => void; function SwapHarness({ initial }: { initial: HTMLDivElement }): JSX.Element { @@ -324,15 +324,12 @@ describe('PinnedScrollbar', () => { expect(document.getElementById(controls!)).toBe(second); unmount(); - first.remove(); - second.remove(); }); - // Reverse of the host-supplied-id case: the stamp happens first and the host - // takes the id over afterwards, so the remount sees an id it did not write. + // The host takes the id over after the first mount stamped one. test('aria-controls follows an id the host assigns after the first mount stamped one', async () => { const ref = makeScrollRef(1000, 400); - document.body.appendChild(ref.current!); + attach(ref.current!); const first = renderWithTheme(); await act(async () => { @@ -351,15 +348,13 @@ describe('PinnedScrollbar', () => { expect(document.getElementById(thumb.getAttribute('aria-controls')!)).toBe(ref.current); second.unmount(); - ref.current!.remove(); }); - // Control, green before and after the fix: two scrollbars on one page each - // point at their own container. - test('two concurrent scrollbars each control their own container (control)', async () => { + test('two concurrent scrollbars each control their own container', async () => { const a = makeScrollRef(1000, 400); const b = makeScrollRef(1000, 400); - document.body.append(a.current!, b.current!); + attach(a.current!); + attach(b.current!); const firstRender = renderWithTheme(); const secondRender = renderWithTheme(); @@ -378,21 +373,13 @@ describe('PinnedScrollbar', () => { firstRender.unmount(); secondRender.unmount(); - a.current!.remove(); - b.current!.remove(); }); - // Control: the effect bails at `if (!el) return` before it can stamp an id or - // call setControlsId, and `visible` never flips, so no thumb, and no - // aria-controls, is emitted at all. Green before and after the fix; it pins - // that the new state doesn't leak an attribute onto a scrollbar that the - // early return means was never rendered. - test('emits no thumb and no aria-controls when the scroll ref is empty (control)', async () => { + // An empty scroll ref renders no scrollbar. + test('emits no thumb and no aria-controls when the scroll ref is empty', () => { const ref = { current: null } as React.RefObject; const { container, unmount } = renderWithTheme(); - await act(async () => {}); - expect(container.querySelector('.rdt_pinnedScrollbarTrack')).toBeNull(); expect(container.querySelector('.rdt_pinnedScrollbarThumb')).toBeNull(); expect(container.querySelector('[aria-controls]')).toBeNull(); diff --git a/src/components/PinnedScrollbar.tsx b/src/components/PinnedScrollbar.tsx index d01aa59f..ba3066c8 100644 --- a/src/components/PinnedScrollbar.tsx +++ b/src/components/PinnedScrollbar.tsx @@ -13,8 +13,7 @@ export default function PinnedScrollbar({ rightInset, }: PinnedScrollbarProps): JSX.Element | null { const scrollContainerId = React.useId(); - // The id the thumb points at. Only equals scrollContainerId when this - // component is the one that labelled the container. See the sync effect. + // The scroll container id aria-controls points at. const [controlsId, setControlsId] = React.useState(scrollContainerId); const trackRef = React.useRef(null); const thumbRef = React.useRef(null); @@ -65,10 +64,8 @@ export default function PinnedScrollbar({ if (!el.id) { el.id = scrollContainerId; } - // The container keeps whatever id it already had, a host-supplied one or - // one left behind by a previous mount (useId hands out a fresh value each - // time). Point aria-controls at the id that is actually on the element, or - // it dangles and assistive tech can't resolve the scrollbar's target. + // An existing container id is preserved and is what aria-controls must + // name, or the reference dangles. setControlsId(el.id); el.addEventListener('scroll', update, { passive: true }); const ro = new ResizeObserver(update); From bf75ce762183b63a2acfd7fc9f161d9cb34afc0d Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Wed, 23 Sep 2026 00:43:40 +0000 Subject: [PATCH 7/8] test: brace the afterEach cleanup loop and type attach generically The repo's curly rule requires braces on every for-of, and CI lint failed on the one-line cleanup loop. attach now returns the element type it was given, so the swap harness gets an HTMLDivElement back and tsc --noEmit is green alongside lint. --- src/__tests__/pinning.test.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/__tests__/pinning.test.tsx b/src/__tests__/pinning.test.tsx index 2e3f1303..ac9a22ff 100644 --- a/src/__tests__/pinning.test.tsx +++ b/src/__tests__/pinning.test.tsx @@ -140,13 +140,15 @@ function makeScrollRef(scrollWidth = 1000, clientWidth = 400): React.RefObject { const attached: HTMLElement[] = []; - const attach = (el: HTMLElement): HTMLElement => { + const attach = (el: T): T => { document.body.appendChild(el); attached.push(el); return el; }; afterEach(() => { - for (const el of attached.splice(0)) el.remove(); + for (const el of attached.splice(0)) { + el.remove(); + } }); test('renders null before ResizeObserver fires (no overflow detected yet)', () => { From 026dd5a48588b47560ffe78e13158bcbfa341580 Mon Sep 17 00:00:00 2001 From: askalf <263217947+askalf@users.noreply.github.com> Date: Thu, 24 Sep 2026 20:21:21 +0000 Subject: [PATCH 8/8] docs: file the pinned scrollbar fix under a new 8.11.1 changelog entry --- CHANGELOG.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 804563cd..c82a93f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ A summary of notable changes per release. For the full commit history see the [repository on GitHub](https://github.com/jbetancur/react-data-table-component/commits/master). +## 8.11.1 + +### Bug fixes + +- **Pinned scrollbar** now sets `aria-controls` to the scroll container's real id. When the container already carried an id, or was labelled again after an unpin and re-pin, the thumb kept pointing at a generated id no element had, so assistive technology could not resolve what the scrollbar controlled. + +--- + ## 8.11.0 ### Behavior changes @@ -41,7 +49,6 @@ These are accessibility fixes, but they change the rendered markup, so tests tha ### Bug fixes -- **Pinned scrollbar** now sets `aria-controls` to the scroll container's real id. When the container already carried an id, or was labelled again after an unpin and re-pin, the thumb kept pointing at a generated id no element had, so assistive technology could not resolve what the scrollbar controlled. - Set filter checkboxes now use the table's own checkbox styling instead of the browser's native control, so they match the row selection checkboxes and follow the theme. → [Filtering](/docs/filtering) - Keyboard focus in the context menu is now distinguishable from mouse hover. Both painted the same background, so arrowing through the menu while the pointer rested on another item highlighted two items at once. → [Context menu](/docs/context-menu) - Checkboxes now show a focus ring when tabbed to. The styled checkbox hides the real input and draws its own box, which had no focus style, so keyboard users tabbing through row selection or a set filter checklist could not see where they were. → [Row selection](/docs/selection)