Stop buttons behind a modal firing from the keyboard

A declined PNI returned without redrawing, so its stale button stayed
focused. With a DE-KICKS quote open (game paused, nothing redraws),
Enter or Space kept pressing it, and each press toasted another decline.
Redraw after a decline, move focus into a modal when it opens, and
ignore activations of anything outside an open modal.
This commit is contained in:
Frederic Jung 2026-10-25 16:49:39 +01:00
parent 055a975851
commit 27c1d73b56
No known key found for this signature in database
3 changed files with 26 additions and 3 deletions

View file

@ -564,3 +564,24 @@ test('#64 leased and own land fiber stay near their route next to a trench full
for (const id of ['d1', 'd2']) assert.ok(r(id) < 0.35, `${id} bulges ${r(id).toFixed(2)}× the route`);
assert.deepEqual(errors, []);
});
test('buttons behind an open modal stay quiet, and a declined PNI clears its stale button', () => {
const { ev, errors } = load();
ev("ACT.start({});S.cash=1e7;for(const g of GOALS)S.done[g.id]=0;ACT.launchBB({city:'fra'});ACT.buildPop({city:'mrs'});ACT.buyTransit({city:'mrs',net:'cog',tier:1});compute()");
// the PNI button was drawn while Tangerine still wanted our traffic; by the click it doesn't
ev("R.demTo.tng=50;UI.sel={type:'city',id:'mrs'};UI.tab='peer';renderAll();R.demTo.tng=0;window.__n=0;const o=toast;toast=function(h){if(/declined/.test(h))window.__n++;return o.apply(this,arguments);}");
const btn = "document.querySelector('#panel [data-act=pni][data-args*=tng]')";
assert.ok(ev(`!!${btn}`), 'a stale button to start with');
ev(`${btn}.focus();${btn}.click()`);
assert.equal(ev('__n'), 1);
assert.equal(ev(`!!${btn}`), false, 'the panel redraws and shows why instead');
// with a modal open, a click (from Enter, Space or anything else) on something behind it does nothing
ev("R.demTo.tng=50;renderAll();R.demTo.tng=0;const b=" + btn + ";b.focus();ACT.buyIx({city:ixIdsIn('mrs')[0],tier:1})");
assert.equal(ev("$('modal').hidden"), false, 'the DE-KICKS quote is open');
assert.notEqual(ev("document.activeElement&&document.activeElement.dataset.act"), 'pni', 'focus left the hidden button');
ev(`for(let i=0;i<5;i++)document.querySelector('#panel [data-act=pni][data-args*=tng]').click()`);
assert.equal(ev('__n'), 1, 'no declines from behind the quote');
ev("document.querySelector('#modal [data-act=dkWalk]').click()");
assert.equal(ev("$('modal').hidden"), true, 'buttons inside the modal still work');
assert.deepEqual(errors, []);
});