Vue: the credits line and its Data attribution list are a single-file component

mountCreditsView() keeps its signature and stays the owner: it computes the
credits shown once each, keeps the list's open state and its focus, takes the
expand and close clicks and Escape, and renders CreditsView synchronously
(as the weather readout is rendered), so focus moves as soon as a change
returns. The view teleports the line and the list to the end of the body, as
the script appended them, so the page's rules that select them as children
of the body still apply; CreditItem draws one credit (its logo or its text,
only its linked words linked, links and logos kept only for a safe scheme).

The ids, classes, roles, aria attributes and text are unchanged. The list's
close button is a UiCloseButton with bare, keeping the browser's padding, so
it only gains the kit's classes, which carry no rules. The expand button
stays a plain button: its words are its content, which a UiButton slot would
not word again when the owner renders a new locale. The list's items are
keyed by credit, so a link that keeps its place keeps focus through a
redraw; one that goes still hands focus to the close button.

New tests: the line and list follow the locale, and they are the last of the
body with the kit's close button.

Co-authored-by: Manjunath Paparaju <[email protected]>
This commit is contained in:
Sameh KhamisandManjunath Paparaju committed 2026-11-19 01:58:47 -08:00
1 parent 1f34210f71
commit 0b06bc6645
7 files changed
+267 -126

No files matched your search

+56 -1
View File
@@ -4,6 +4,7 @@ import assert from 'node:assert/strict';
import { mountCreditsView } from './creditsView.js';
import { bindRenderer } from '../render/rendererOf.js';
import { createStubRenderer } from '../render/stub/index.js';
import { setLocale } from '../i18n/index.js';
function scene() {
document.body.replaceChildren();
@@ -118,10 +119,12 @@ test('focus in the list stays in it as it redraws, and goes to the line as it em
const off = mountCreditsView(viewer);
const panel = document.getElementById('gev-credits-panel');
document.querySelector('.gev-credits-expand').click();
panel.querySelector('li a').focus();
const link = panel.querySelector('li a');
link.focus();
const removeOther = renderer.credits.addStatic({ text: 'NOAA' });
assert.equal(panel.hidden, false);
assert.ok(panel.contains(document.activeElement), 'still in the list');
assert.equal(document.activeElement, link, 'the focused link keeps it');
remove();
removeOther();
assert.equal(panel.hidden, true);
@@ -152,3 +155,55 @@ test('a credit with linked words links only those words', () => {
);
off();
});
test('the line and its list follow the locale', () => {
const { viewer, renderer } = scene();
renderer.credits.addStatic({ text: 'NOAA' });
const off = mountCreditsView(viewer);
const expand = document.querySelector('.gev-credits-expand');
const close = document.querySelector('.gev-credits-close');
try {
setLocale('fr');
assert.equal(expand.textContent, 'Attribution des données');
assert.equal(
document.getElementById('gev-credits-panel-title').textContent,
'Données fournies par\u202f:',
);
assert.equal(
close.getAttribute('aria-label'),
"Fermer l'attribution des données",
);
} finally {
setLocale('en');
}
assert.equal(expand.textContent, 'Data attribution');
off();
});
test('the line and its list are the last of the body, and its close button is the kit’s', () => {
const { viewer, renderer } = scene();
document.body.append(document.createElement('main'));
renderer.credits.addStatic({ text: 'NOAA' });
const off = mountCreditsView(viewer);
const children = [...document.body.children];
assert.deepEqual(
children.slice(-2).map((element) => element.id),
['gev-credits', 'gev-credits-panel'],
'the page’s rules select them as children of the body',
);
const close = document.querySelector('.gev-credits-close');
assert.ok(close.classList.contains('ui-button'), 'a UiCloseButton');
assert.equal(close.type, 'button');
assert.equal(close.textContent, '×');
assert.equal(close.hasAttribute('title'), false, 'no tip');
assert.equal(
close.classList.contains('ui-close-button'),
false,
'bare: it keeps the browser’s padding',
);
off();
assert.deepEqual(
[...document.body.children].map((element) => element.tagName),
['MAIN'],
);
});