A failed fallback is not tried again, and focus stays in the credits list as it redraws

This commit is contained in:
Sameh Khamis committed 2026-11-10 18:57:47 -08:00
1 parent e440f3dddb
commit df8728d0ad
4 files changed
+49 -5

No files matched your search

+7 -2
View File
@@ -60,6 +60,8 @@ export function mountCreditsView(viewer, { root = document.body } = {}) {
const bar = doc.createElement('div');
bar.id = 'gev-credits';
bar.className = 'gev-credits';
// Takes focus back from an emptied list when the line has no link.
bar.tabIndex = -1;
const line = doc.createElement('span');
line.className = 'gev-credits-line';
const expand = doc.createElement('button');
@@ -105,6 +107,7 @@ export function mountCreditsView(viewer, { root = document.body } = {}) {
};
const render = (all) => {
const focused = panel.contains(doc.activeElement);
const shown = distinct(Array.isArray(all) ? all : []);
const inline = shown.filter((credit) => credit.inline);
const listed = shown.filter((credit) => !credit.inline);
@@ -124,9 +127,11 @@ export function mountCreditsView(viewer, { root = document.body } = {}) {
expand.hidden = listed.length === 0;
if (expand.hidden && !panel.hidden) {
// Focus in the list goes back to the line, not to the page.
const focused = panel.contains(doc.activeElement);
setOpen(false);
if (focused) line.querySelector('a')?.focus();
if (focused) (line.querySelector('a') ?? bar).focus();
} else if (focused && !panel.contains(doc.activeElement)) {
// A link that focus was on was redrawn: focus stays in the list.
close.focus();
}
};
+25
View File
@@ -107,3 +107,28 @@ test('the credits line is placed wherever the renderer’s own display is', asyn
}
assert.deepEqual(missing, []);
});
test('focus in the list stays in it as it redraws, and goes to the line as it empties', () => {
const { viewer, renderer } = scene();
renderer.credits.addStatic({ text: 'Esri', inline: true });
const remove = renderer.credits.addStatic({
text: 'OSM',
href: 'https://www.openstreetmap.org/copyright',
});
const off = mountCreditsView(viewer);
const panel = document.getElementById('gev-credits-panel');
document.querySelector('.gev-credits-expand').click();
panel.querySelector('li a').focus();
const removeOther = renderer.credits.addStatic({ text: 'NOAA' });
assert.equal(panel.hidden, false);
assert.ok(panel.contains(document.activeElement), 'still in the list');
remove();
removeOther();
assert.equal(panel.hidden, true);
assert.equal(
document.activeElement,
document.getElementById('gev-credits'),
'a line with no link takes it',
);
off();
});