) => void
/**
* Roving-focus membership for {@link useListNavigation}: the title button
@@ -160,14 +172,28 @@ export interface ListRowProps extends DataAttributes {
export function ListRow(props: ListRowProps): ReactNode {
const {
leading, title, titleData, titleLabel, subtitle, meta, actions, titleAs = 'plain', onTitleClick,
- selected, dimmed, onContextMenu, primary, className, ...dataProps
+ selected, dimmed, disabled, onContextMenu, primary, className,
+ 'aria-expanded': expanded, 'aria-controls': controls, 'aria-label': ariaLabel,
+ ...dataProps
} = props
+ const label = ariaLabel ?? titleLabel
+ // The control semantics belong to whichever element is the control: the
+ // title button when the row navigates, the shell otherwise.
+ const controlAria = titleAs === 'button'
+ ? {}
+ : {
+ ...(expanded === undefined ? {} : { 'aria-expanded': expanded }),
+ ...(controls === undefined ? {} : { 'aria-controls': controls }),
+ ...(label === undefined ? {} : { 'aria-label': label }),
+ }
return (
{leading !== undefined && {leading}}
@@ -180,7 +206,11 @@ export function ListRow(props: ListRowProps): ReactNode {
type="button"
{...titleData}
className={clsx(css.listRowMain, css.listRowTitle)}
- {...(titleLabel === undefined ? {} : { 'aria-label': titleLabel, title: titleLabel })}
+ {...(label === undefined ? {} : { 'aria-label': label })}
+ {...(titleLabel === undefined ? {} : { title: titleLabel })}
+ {...(expanded === undefined ? {} : { 'aria-expanded': expanded })}
+ {...(controls === undefined ? {} : { 'aria-controls': controls })}
+ disabled={disabled}
{...(primary === undefined ? {} : { 'data-list-primary': true, tabIndex: primary ? 0 : -1 })}
onClick={onTitleClick}
>
@@ -410,8 +440,8 @@ export interface StatusLineProps {
readonly icon?: ReactNode
readonly meta?: ReactNode
readonly action?: ReactNode
- /** `status` announces changes politely; omit for a purely static footnote. */
- readonly role?: 'status'
+ /** `status` announces changes politely, `alert` interrupts for a failure; omit for a purely static footnote. */
+ readonly role?: 'status' | 'alert'
/** Drop the horizontal padding when the caller's container already has it. */
readonly plain?: boolean
readonly className?: string
diff --git a/tests/ui-kit.spec.tsx b/tests/ui-kit.spec.tsx
index 36980095..a6887ece 100644
--- a/tests/ui-kit.spec.tsx
+++ b/tests/ui-kit.spec.tsx
@@ -12,7 +12,7 @@ import { createElement, type ReactNode } from 'react'
import { createRoot, type Root } from 'react-dom/client'
import { act } from 'react-dom/test-utils'
import { setupReactAct } from './test-utils.ts'
-import { Chip, ConfirmDialog, DownloadLink, IconButton, Notice, SectionHeader, StatusBadge } from '../src/client/ui/kit.tsx'
+import { Chip, ConfirmDialog, DownloadLink, FileAttachmentChip, IconButton, Notice, SectionHeader, StatusBadge } from '../src/client/ui/kit.tsx'
import { invalidateGitStatus, statusOfXY, useGitStatus, type GitStatusView } from '../src/client/ui/git-status.ts'
import type { GitStatusResult } from '../src/client/api.ts'
@@ -357,3 +357,30 @@ describe('DownloadLink', () => {
await unmount()
})
})
+
+describe('FileAttachmentChip', () => {
+ it('renders a static file card with the host glyph, name and size — never a control', async () => {
+ const { container, unmount } = await mount(createElement(FileAttachmentChip, {
+ name: 'report.pdf', size: '1.2 MB', title: '/tmp/report.pdf',
+ }))
+ const chip = container.querySelector('[class*="fileChip"]')!
+ expect(chip.tagName).toBe('SPAN')
+ expect(chip.getAttribute('title')).toBe('/tmp/report.pdf')
+ expect(container.querySelector('[class*="fileChipName"]')!.textContent).toBe('report.pdf')
+ expect(container.querySelector('[class*="fileChipSize"]')!.textContent).toBe('1.2 MB')
+ expect(chip.querySelector('svg')).not.toBeNull()
+ expect(container.querySelector('button, a')).toBeNull()
+ await unmount()
+ })
+
+ it('marks an unavailable attachment without dropping its identity', async () => {
+ const { container, unmount } = await mount(createElement(FileAttachmentChip, {
+ name: 'gone.png', unavailable: true,
+ }))
+ const chip = container.querySelector('[class*="fileChip"]')!
+ expect(chip.dataset.unavailable).toBe('true')
+ expect(chip.textContent).toContain('gone.png')
+ expect(container.querySelector('[class*="fileChipSize"]')).toBeNull()
+ await unmount()
+ })
+})
diff --git a/tests/ui-patterns.spec.tsx b/tests/ui-patterns.spec.tsx
index 7a51ba6b..0576ec10 100644
--- a/tests/ui-patterns.spec.tsx
+++ b/tests/ui-patterns.spec.tsx
@@ -138,6 +138,29 @@ describe('ListRow', () => {
view = renderRoot(createElement(ListRow, { title: 'Row', 'data-clue-result-row': 'clue-1' }))
expect(view.container.querySelector('[data-clue-result-row]')).not.toBeNull()
})
+
+ it('carries a collapsible header expanded state on its one button', () => {
+ view = renderRoot(createElement(ListRow, {
+ title: 'Environment',
+ titleAs: 'button',
+ 'aria-expanded': true,
+ 'aria-controls': 'panel-body',
+ 'aria-label': 'Environment section',
+ }))
+ const button = view.container.querySelector('button')!
+ expect(button.getAttribute('aria-expanded')).toBe('true')
+ expect(button.getAttribute('aria-controls')).toBe('panel-body')
+ expect(button.getAttribute('aria-label')).toBe('Environment section')
+ // The row shell itself is not the control, so it must not claim the state.
+ expect(byClass(view.container, 'listRow')!.hasAttribute('aria-expanded')).toBe(false)
+ })
+
+ it('renders a disabled row as inert while keeping its title readable', () => {
+ view = renderRoot(createElement(ListRow, { title: 'Locked', titleAs: 'button', disabled: true }))
+ expect((view.container.querySelector('button') as HTMLButtonElement).disabled).toBe(true)
+ expect(byClass(view.container, 'listRow')!.dataset.disabled).toBe('true')
+ expect(byClass(view.container, 'listRow')!.textContent).toContain('Locked')
+ })
})
describe('EmptyState', () => {
@@ -300,6 +323,14 @@ describe('StatusLine', () => {
expect(view.container.querySelector('[role="status"]')).not.toBeNull()
})
+ it('can interrupt with an alert when the line reports a failure', () => {
+ view = renderRoot(createElement(StatusLine, { text: 'Upload failed', tone: 'error', role: 'alert' }))
+ const line = view.container.querySelector('[role="alert"]')
+ expect(line).not.toBeNull()
+ expect(line!.getAttribute('role')).toBe('alert')
+ expect(view.container.querySelector('[role="status"]')).toBeNull()
+ })
+
it('separates the trailing action from the text', () => {
view = renderRoot(createElement(StatusLine, {
text: 'Failed', tone: 'error',