Skip to content

Commit 44a34e3

Browse files
committed
fix(AnalyticalTable - useF2CellEdit): avoid literal "undefined" in F2 cell edit aria-label
1 parent 5ee6370 commit 44a34e3

3 files changed

Lines changed: 56 additions & 2 deletions

File tree

‎packages/main/src/components/AnalyticalTable/pluginHooks/useF2CellEdit.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ export const useF2CellEdit = (hooks: ReactTableHooks) => {
7979
const inputName =
8080
typeof interactiveElementName === 'function' ? interactiveElementName(cell) : interactiveElementName;
8181
const ariaLabel =
82-
(interactiveElementName ? i18nBundle.getText(INCLUDES_X, inputName) : '') + ' ' + props['aria-label'];
82+
[interactiveElementName ? i18nBundle.getText(INCLUDES_X, inputName) : '', props['aria-label']]
83+
.filter(Boolean)
84+
.join(' ') || undefined;
8385

8486
const handleKeyDown: KeyboardEventHandler<HTMLDivElement> = (e) => {
8587
if (state.cellContentTabIndex === 0 && NAVIGATION_KEYS.has(e.key) && !e.key.includes('Arrow')) {

‎packages/main/src/components/AnalyticalTable/test/AnalyticalTable.gallery.tsx‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import { useCallback, useMemo, useRef, useState } from 'react';
22
import { AnalyticalTableSelectionMode } from '../../../enums/AnalyticalTableSelectionMode.js';
33
import { AnalyticalTableSubComponentsBehavior } from '../../../enums/AnalyticalTableSubComponentsBehavior.js';
44
import { Button } from '../../../webComponents/Button/index.js';
5+
import { Link } from '../../../webComponents/Link/index.js';
56
import { Panel } from '../../../webComponents/Panel/index.js';
67
import { Tab } from '../../../webComponents/Tab/index.js';
78
import { TabContainer } from '../../../webComponents/TabContainer/index.js';
89
import { AnalyticalTable } from '../index.js';
9-
import type { AnalyticalTableColumnDefinition, AnalyticalTableInstance, AnalyticalTablePropTypes } from '../index.js';
10+
import type {
11+
AnalyticalTableCellInstance,
12+
AnalyticalTableColumnDefinition,
13+
AnalyticalTableInstance,
14+
AnalyticalTablePropTypes,
15+
} from '../index.js';
1016
import * as AnalyticalTableHooks from '../pluginHooks/AnalyticalTableHooks.js';
1117
import type {
1218
AnalyticalTableStickyAutoToggleDetail,
@@ -380,3 +386,24 @@ export const LoadingPlaceholderHarness = (props: Partial<AnalyticalTablePropType
380386
{...props}
381387
/>
382388
);
389+
390+
const LinkCell = (props: AnalyticalTableCellInstance) => {
391+
const callbackRef = AnalyticalTableHooks.useF2CellEdit.useCallbackRef(props);
392+
return (
393+
<Link href="#review" ref={callbackRef}>
394+
{props.value}
395+
</Link>
396+
);
397+
};
398+
399+
const f2Columns: AnalyticalTableColumnDefinition[] = [
400+
// Interactive column without a `cellLabel` — the hook builds the cell `aria-label` from `interactiveElementName`.
401+
{ Header: 'Title', accessor: 'title', Cell: LinkCell, interactiveElementName: 'Link' },
402+
// Plain column with neither `interactiveElementName` nor `cellLabel` — must keep its `aria-labelledby`.
403+
{ Header: 'Status', accessor: 'status' },
404+
];
405+
406+
const f2Data = [{ title: 'Annual Review', status: 'open' }];
407+
const f2TableHooks = [AnalyticalTableHooks.useF2CellEdit];
408+
409+
export const F2CellEditHarness = () => <AnalyticalTable columns={f2Columns} data={f2Data} tableHooks={f2TableHooks} />;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, test } from '../../../../../../playwright/fixtures/gallery-fixtures.js';
2+
3+
const STORY = 'AnalyticalTable/F2CellEditHarness';
4+
5+
test.describe('AnalyticalTable useF2CellEdit — cell aria-label', () => {
6+
test('interactive cell without cellLabel gets a clean aria-label (no literal "undefined")', async ({
7+
mount,
8+
page,
9+
}) => {
10+
await mount(STORY);
11+
12+
// First body row (header is aria-rowindex 1), first column = the Link cell.
13+
const titleCell = page.locator('[aria-rowindex="2"] > [aria-colindex="1"]');
14+
await expect(titleCell).toHaveAttribute('aria-label', 'Includes Link');
15+
expect(await titleCell.getAttribute('aria-label')).not.toContain('undefined');
16+
});
17+
18+
test('non-interactive cell keeps its aria-labelledby and gets no aria-label', async ({ mount, page }) => {
19+
await mount(STORY);
20+
21+
const statusCell = page.locator('[aria-rowindex="2"] > [aria-colindex="2"]');
22+
await expect(statusCell).not.toHaveAttribute('aria-label');
23+
await expect(statusCell).toHaveAttribute('aria-labelledby', /\S/);
24+
});
25+
});

0 commit comments

Comments
 (0)