Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(frontend-components): r1-m1 label grouped table relationships

Josué004a7d649d32
diff --git a/control-ui/components/__tests__/FrontendComponents.test.tsx b/control-ui/components/__tests__/FrontendComponents.test.tsx
index 8a69fbd8d..e332f80e8 100644
--- a/control-ui/components/__tests__/FrontendComponents.test.tsx
+++ b/control-ui/components/__tests__/FrontendComponents.test.tsx
@@ -59,7 +59,7 @@ describe('shared frontend components', () => {
const alphaDisclosure = screen.getByRole('button', { name: 'Expand Alpha records' })
expect(alphaDisclosure).toHaveAttribute('aria-expanded', 'false')
- expect(alphaDisclosure).toHaveAttribute('aria-controls', 'eft-table-group-alpha-rows')
+ expect(alphaDisclosure.getAttribute('aria-controls')).toMatch(/alpha-rows$/)
expect(document.querySelectorAll('table > tbody > tr')).toHaveLength(2)
expect(screen.queryByText('Alpha child action')).toBeNull()
expect(screen.queryByText('Beta child')).toBeNull()
@@ -104,14 +104,51 @@ describe('shared frontend components', () => {
'aria-expanded',
'true'
)
- expect(screen.getByText('Alpha child action').closest('tr')?.parentElement).toHaveAttribute(
- 'id',
- 'eft-table-group-alpha-rows'
- )
+ const alphaChildBody = screen.getByText('Alpha child action').closest('tr')?.parentElement
+ const collapseAlpha = screen.getByRole('button', { name: 'Collapse Alpha records' })
+ expect(alphaChildBody).toHaveAttribute('id', collapseAlpha.getAttribute('aria-controls'))
+ expect(alphaChildBody).toHaveAttribute('aria-labelledby', collapseAlpha.id)
expect(screen.queryByText('Beta child')).toBeNull()
fireEvent.click(screen.getByRole('button', { name: 'Edit Alpha' }))
expect(onAlphaExpandedChange).toHaveBeenCalledTimes(1)
+
+ fireEvent.click(collapseAlpha)
+ expect(onAlphaExpandedChange).toHaveBeenLastCalledWith(false)
+ })
+
+ it('uses unique, labelled rowgroup relationships across table instances', () => {
+ render(
+ <>
+ {[1, 2].map(instance => (
+ <DataTable key={instance}>
+ <GroupedTableBody
+ colSpan={1}
+ disclosureLabel={() => 'Collapse Shared records'}
+ expanded
+ groupId="shared"
+ onExpandedChange={() => undefined}
+ summary={`Shared ${instance}`}
+ >
+ <tr>
+ <td>Child {instance}</td>
+ </tr>
+ </GroupedTableBody>
+ </DataTable>
+ ))}
+ </>
+ )
+
+ const disclosures = screen.getAllByRole('button', { name: 'Collapse Shared records' })
+ const rowgroups = screen.getAllByRole('rowgroup', { name: 'Collapse Shared records' })
+ const controlledIds = disclosures.map(disclosure => disclosure.getAttribute('aria-controls'))
+
+ expect(new Set(controlledIds).size).toBe(2)
+ expect(rowgroups).toHaveLength(2)
+ disclosures.forEach((disclosure, index) => {
+ expect(rowgroups[index]).toHaveAttribute('id', controlledIds[index])
+ expect(rowgroups[index]).toHaveAttribute('aria-labelledby', disclosure.id)
+ })
})
it('owns the canonical viewport class and preserves semantic modifiers', () => {
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 03eccd756..74da16267 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.577",
+ "version": "0.1.578",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.577",
+ "version": "0.1.578",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 3028160ce..1b1fd6549 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.577",
+ "version": "0.1.578",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/packages/frontend-components/src/table/grouped.tsx b/packages/frontend-components/src/table/grouped.tsx
index 0d0262f3f..1b247b70e 100644
--- a/packages/frontend-components/src/table/grouped.tsx
+++ b/packages/frontend-components/src/table/grouped.tsx
@@ -1,6 +1,6 @@
'use client'
-import { Fragment } from 'react'
+import { Fragment, useId } from 'react'
import type { GroupedTableBodyProps } from './types'
import { classNames } from './utils'
@@ -16,7 +16,10 @@ export function GroupedTableBody({
onExpandedChange,
summary,
}: GroupedTableBodyProps) {
- const childRowsId = `eft-table-group-${groupId}-rows`
+ const instanceId = useId().replaceAll(':', '')
+ const idBase = `eft-table-group-${instanceId}-${encodeURIComponent(groupId)}`
+ const disclosureId = `${idBase}-disclosure`
+ const childRowsId = `${idBase}-rows`
return (
<Fragment>
@@ -28,6 +31,7 @@ export function GroupedTableBody({
aria-expanded={expanded}
aria-label={disclosureLabel(expanded)}
className={classNames('eft-table-group__disclosure', disclosureClassName)}
+ id={disclosureId}
onClick={event => {
event.stopPropagation()
onExpandedChange(!expanded)
@@ -43,6 +47,7 @@ export function GroupedTableBody({
</tr>
</tbody>
<tbody
+ aria-labelledby={disclosureId}
className={classNames('eft-table-group__children', childBodyClassName)}
id={childRowsId}
>