Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/34722-installed-apps-module-toggle-aria-controls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@object-ui/app-shell': patch
---

fix(app-shell): the Installed Apps module toggle names the module lines it shows

Clause-②: no
Metadata-protocol: none

In Setup › Installed Apps, the button that shows and hides an app's modules carried `aria-controls` with an id that no element had, so a screen reader was pointed at nothing. Each module line now has its own id. While the modules are shown, the button's `aria-controls` lists those ids. While they are hidden, the lines are not drawn and the button has no `aria-controls`. `aria-expanded` is unchanged.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import '@testing-library/jest-dom/vitest';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
import axe from 'axe-core';
import { I18nProvider } from '@object-ui/i18n';

vi.mock('@object-ui/auth', async (importOriginal) => ({
Expand Down Expand Up @@ -346,6 +347,35 @@ describe('Setup → Installed Apps: an app is one line, its modules folded under
for (const id of MODULE_IDS) expect(screen.queryByTestId(`pkg-row-${id}`)).toBeNull();
});

it('the toggle names the module lines it shows in aria-controls, and names none while they are hidden', async () => {
await serve({ packages: [HOTCRM, ...MODULES, TODO] });
renderAt(SETUP_URL);
await settled();

const toggle = screen.getByTestId(`pkg-modules-toggle-${HOTCRM_ID}`);
expect(toggle).not.toHaveAttribute('aria-controls');

fireEvent.click(toggle);
const ids = (toggle.getAttribute('aria-controls') ?? '').split(' ');
// Every id resolves to a drawn module line of this app, one per module.
const named = ids.map((id) => document.getElementById(id));
expect(named.map((el) => el?.getAttribute('data-testid')).sort()).toEqual(
MODULE_IDS.map((id) => `pkg-row-${id}`).sort(),
);
for (const el of named) expect(el).toHaveAttribute('data-module-of', HOTCRM_ID);

// axe judges the IDREFs of an expanded control: none may dangle.
const res = await axe.run(screen.getByTestId('pkg-installed-apps-table'), {
runOnly: { type: 'rule', values: ['aria-valid-attr-value'] },
});
expect(res.violations.map((v) => v.nodes.map((n) => n.html.slice(0, 80)))).toEqual([]);
// Control: an empty list is a reading only if the rule judged the toggle.
expect(res.passes.flatMap((r) => r.nodes.map((n) => n.html)).some((h) => h.includes('aria-controls='))).toBe(true);

fireEvent.click(toggle);
expect(toggle).not.toHaveAttribute('aria-controls');
});

it('a module that declares two apps, or none in view, stays a line of its own', async () => {
const twoApps = moduleOf(`${HOTCRM_ID}.bridge`, [HOTCRM_ID, 'com.example.todo']);
const orphan = moduleOf('com.example.lonely', ['com.example.absent']);
Expand Down
19 changes: 18 additions & 1 deletion ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,17 @@ function appOfModule(row: PackageListRow, apps: ReadonlyMap<string, PackageListR
return parents.length === 1 ? parents[0] : null;
}

/**
* The DOM id of a module line in the Installed Apps table: its app's toggle
* lists these ids in `aria-controls` while the modules are shown. `base` is the
* page's `React.useId()`, so a second mounted page never repeats one; the row id
* is percent-encoded, so the id holds no whitespace and stays one token of the
* space-separated IDREF list.
*/
function moduleRowDomId(base: string, rowId: string): string {
return `${base}pkg-module-${encodeURIComponent(rowId)}`;
}

/** Fold each module row under its app ({@link appOfModule}), keeping the rows' order. */
function groupInstalledApps(rows: readonly PackageListRow[]): InstalledAppGroup[] {
const apps = new Map<string, PackageListRow>();
Expand Down Expand Up @@ -1818,6 +1829,7 @@ export function PackagesPage() {
.filter((g): g is InstalledAppGroup & { matchedModules: boolean } => g !== null);
}, [installedAppsView, rows, query]);
const [expandedApps, setExpandedApps] = React.useState<ReadonlySet<string>>(() => new Set());
const moduleIdBase = React.useId();
const toggleApp = (id: string) =>
setExpandedApps((prev) => {
const next = new Set(prev);
Expand Down Expand Up @@ -2128,6 +2140,7 @@ export function PackagesPage() {
key={rowId}
className={cn(p ? 'cursor-pointer' : undefined, module ? 'bg-muted/30' : undefined)}
onClick={p ? () => openDetail(p) : undefined}
id={module ? moduleRowDomId(moduleIdBase, rowId) : undefined}
data-testid={`pkg-row-${rowId}`}
data-module-of={module ? row.id : undefined}
>
Expand All @@ -2139,7 +2152,11 @@ export function PackagesPage() {
size="icon"
className="h-6 w-6 shrink-0"
aria-expanded={open}
aria-controls={`pkg-modules-${rowId}`}
// The module lines it shows and hides: named only while
// they are drawn, since a collapsed group renders none.
aria-controls={
open ? modules.map((m) => moduleRowDomId(moduleIdBase, m.id)).join(' ') : undefined
}
aria-label={
open
? tFormat('engine.packages.installedApps.hideModules', locale, { name: p?.manifest.name || rowId })
Expand Down
Loading