ui: nine leaf files off Semantic, and the components they needed

Phase 2, part 2.  Baseline 72 -> 63.

Migrated: Tables, SortableTable, DonatePage, Share, Headline, ErrorBoundary,
and the QR code, VIN decoder, and temperature calculators.

New in the library, all in the gallery and tested:

  SearchBox     Semantic's `<Search category>`, keeping its grouped `results`
                shape because four call sites already build it.  A real
                combobox: arrows move, Enter takes the highlighted suggestion
                or submits the raw text, Escape closes without clearing.
  Pagination    Semantic's prop names, but onPageChange gets the page number
                rather than an (event, data) pair.
  TabBar        the strip and its house style only; routing stays at the call
                site, which is what decides what is active.
  IconStack     two glyphs composed into one symbol, named once for assistive
                technology (Semantic's IconGroup).
  Table.HeaderCell gains `sorted` and `onSort`.

That last one is a fix, not just a port.  Semantic's `sorted` prop set
`aria-sort`; migrating a table by hand dropped it, leaving a clickable <th>
that no keyboard could reach and no screen reader could describe.  Putting it
in the library means the next table gets it right without anyone remembering.

Night mode holes closed along the way: the QR codes on the donate, share, and
calculator pages are white by necessity — a scanner needs the contrast — and
they render as SVG, which the media filter does not target.  In night mode that
was a lit panel.  They now carry `.media`, so the filter remaps the block as a
unit and the contrast survives the mapping.

Also: `paypal` joins the icon map rather than being imported ad hoc in a page,
and FileBrowser stops passing Semantic-only table props into a DOM element.
This commit is contained in:
Roland 2026-07-30 09:31:15 -06:00 • committed by lrnselfreliance
parent efe84d17f1
commit 18dc90b4c2
19 changed files with 1030 additions and 224 deletions

View file

@ -12,6 +12,11 @@ import {
Confirm,
Header,
Icon,
IconStack,
Pagination,
SearchBox,
TabBar,
tabClassName,
IconButton,
Label,
Message,
@ -280,6 +285,30 @@ describe('Table', () => {
expect(container.querySelector('.wrolpi-row-failed')).toBeInTheDocument();
});
it('makes a sortable column a keyboard-reachable button that announces its state', async () => {
// A click handler on the <th> alone is unreachable by keyboard, and the arrow
// glyph says nothing to a screen reader.
const onSort = jest.fn();
renderUI(<Table>
<Table.Header>
<Table.Row>
<Table.HeaderCell sorted='descending' onSort={onSort}>Size</Table.HeaderCell>
<Table.HeaderCell onSort={jest.fn()}>Name</Table.HeaderCell>
<Table.HeaderCell>Actions</Table.HeaderCell>
</Table.Row>
</Table.Header>
</Table>);
expect(screen.getByRole('columnheader', {name: /Size/})).toHaveAttribute('aria-sort', 'descending');
// Sortable but not currently sorted.
expect(screen.getByRole('columnheader', {name: /Name/})).toHaveAttribute('aria-sort', 'none');
// Not sortable at all.
expect(screen.getByRole('columnheader', {name: 'Actions'})).not.toHaveAttribute('aria-sort');
await userEvent.click(screen.getByRole('button', {name: /Size/}));
expect(onSort).toHaveBeenCalled();
});
it('keeps wide tables from scrolling the page sideways', () => {
const {container} = renderUI(<Table><Table.Body>
<Table.Row><Table.Cell>wide</Table.Cell></Table.Row>
@ -409,6 +438,160 @@ describe('ThemePicker', () => {
});
});
describe('Pagination', () => {
it('reports the current page and moves when one is clicked', async () => {
const onPageChange = jest.fn();
renderUI(<Pagination activePage={3} totalPages={12} onPageChange={onPageChange}/>);
await userEvent.click(screen.getByRole('button', {name: 'Page 5'}));
expect(onPageChange).toHaveBeenCalledWith(5);
});
it('still renders one page when the total is unknown', () => {
// Downloads render the paginator before the first response arrives; collapsing to
// nothing and back shifts the whole page.
renderUI(<Pagination activePage={1} totalPages={undefined} onPageChange={jest.fn()}/>);
expect(screen.getByRole('button', {name: 'Page 1'})).toBeInTheDocument();
});
});
describe('TabBar', () => {
it('marks the active tab with a class the themes key on', () => {
const {container} = renderUI(<TabBar>
<button className={tabClassName(true)}>Videos</button>
<button className={tabClassName(false)}>Channels</button>
</TabBar>);
expect(container.querySelectorAll('.wrolpi-tab')).toHaveLength(2);
expect(container.querySelectorAll('.wrolpi-tab-active')).toHaveLength(1);
});
});
describe('SearchBox', () => {
const results = {
directories: {name: 'Directories', results: [{title: 'videos/'}]},
channels: {name: 'Channels', results: [
{title: 'videos/Wranglerstar', description: 'Wranglerstar'},
{title: 'videos/RoseRed', description: 'RoseRed Homestead'},
]},
};
it('submits what was typed', async () => {
const onSubmit = jest.fn();
renderUI(<SearchBox value='axe' onChange={jest.fn()} onSubmit={onSubmit}/>);
await userEvent.type(screen.getByRole('textbox'), '{Enter}');
expect(onSubmit).toHaveBeenCalledWith('axe');
});
it('shows suggestions under their group headings', async () => {
renderUI(<SearchBox value='vid' onChange={jest.fn()} results={results}
onResultSelect={jest.fn()}/>);
await userEvent.click(screen.getByRole('combobox'));
expect(screen.getByText('Directories')).toBeInTheDocument();
expect(screen.getAllByRole('option')).toHaveLength(3);
});
it('selects a suggestion by click', async () => {
const onResultSelect = jest.fn();
renderUI(<SearchBox value='vid' onChange={jest.fn()} results={results}
onResultSelect={onResultSelect}/>);
await userEvent.click(screen.getByRole('combobox'));
await userEvent.click(screen.getByText('videos/Wranglerstar'));
expect(onResultSelect).toHaveBeenCalledWith(
expect.objectContaining({title: 'videos/Wranglerstar'}));
});
it('moves through suggestions with the arrow keys and takes one with Enter', async () => {
const onResultSelect = jest.fn();
const onSubmit = jest.fn();
renderUI(<SearchBox value='vid' onChange={jest.fn()} results={results}
onResultSelect={onResultSelect} onSubmit={onSubmit}/>);
const input = screen.getByRole('combobox');
await userEvent.click(input);
await userEvent.keyboard('{ArrowDown}{ArrowDown}{Enter}');
expect(onResultSelect).toHaveBeenCalledWith(
expect.objectContaining({title: 'videos/Wranglerstar'}));
// Enter took the highlighted suggestion instead of submitting the raw text.
expect(onSubmit).not.toHaveBeenCalled();
});
it('wraps around rather than stranding the user at the end of the list', async () => {
const onResultSelect = jest.fn();
renderUI(<SearchBox value='vid' onChange={jest.fn()} results={results}
onResultSelect={onResultSelect}/>);
await userEvent.click(screen.getByRole('combobox'));
await userEvent.keyboard('{ArrowUp}{Enter}');
expect(onResultSelect).toHaveBeenCalledWith(
expect.objectContaining({title: 'videos/RoseRed'}));
});
it('closes on Escape without clearing what was typed', async () => {
const onChange = jest.fn();
renderUI(<SearchBox value='vid' onChange={onChange} results={results}
onResultSelect={jest.fn()}/>);
await userEvent.click(screen.getByRole('combobox'));
await userEvent.keyboard('{Escape}');
expect(screen.queryByRole('option')).not.toBeInTheDocument();
expect(screen.getByRole('combobox')).toHaveValue('vid');
expect(onChange).not.toHaveBeenCalled();
});
it('says it is searching rather than "no results" while suggestions are pending', async () => {
renderUI(<SearchBox value='vid' onChange={jest.fn()} results={{}} loading
onResultSelect={jest.fn()}/>);
await userEvent.click(screen.getByRole('combobox'));
expect(screen.getByText(/searching/i)).toBeInTheDocument();
});
it('clears the input and submits the empty search', async () => {
const onChange = jest.fn();
const onSubmit = jest.fn();
renderUI(<SearchBox value='axe' onChange={onChange} onSubmit={onSubmit} clearable/>);
await userEvent.click(screen.getByRole('button', {name: 'Clear search'}));
expect(onChange).toHaveBeenCalledWith('');
expect(onSubmit).toHaveBeenCalledWith('');
});
it('is a plain search field when no suggestions are wired up', () => {
// Without this, a box that can never show options still claims to be a combobox.
renderUI(<SearchBox value='' onChange={jest.fn()} onSubmit={jest.fn()}/>);
expect(screen.queryByRole('combobox')).not.toBeInTheDocument();
expect(screen.getByRole('textbox')).toBeInTheDocument();
});
});
describe('IconStack', () => {
it('names the pair once, and hides the corner glyph from assistive tech', () => {
const {container} = renderUI(
<IconStack corner={<Icon name='question'/>} label='WiFi status unknown'>
<Icon name='wifi'/>
</IconStack>
);
expect(screen.getByRole('img', {name: 'WiFi status unknown'})).toBeInTheDocument();
expect(container.querySelector('.wrolpi-icon-stack-corner')).toHaveAttribute('aria-hidden', 'true');
});
});
describe('Confirm', () => {
it('names the action on its confirming button', async () => {
const onConfirm = jest.fn();