Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

a11y: the Cabinet scroll bars and the city panel focus drop (Refs #41) (#1453)

EllaSharakanskid489b36d54cb
diff --git a/changelog.d/a11y-keyboard-focus-41.md b/changelog.d/a11y-keyboard-focus-41.md
new file mode 100644
index 000000000..01de08fa0
--- /dev/null
+++ b/changelog.d/a11y-keyboard-focus-41.md
@@ -0,0 +1,8 @@
+### Fixed
+
+- Keyboard: the Cabinet's seat and candidate lists no longer put their scroll bars in the Tab order, so Tab goes from
+ the last row straight to the next control instead of stopping on a bar that cannot be used from the keyboard.
+- Keyboard: a city or site panel press that leaves its own button gone or disabled no longer drops the focus. The
+ Assign stepper's minus disables itself at zero, Build disables every Build in the part once one group is ordered,
+ and Stop and a project's Cancel leave only a state line; in each case the focus now goes to the nearest control that
+ can take it, so the following Tab carries on instead of starting again at the first screen.
diff --git a/docs/accessibility-audit-2026-10-14.md b/docs/accessibility-audit-2026-10-14.md
index 2c4ca7b88..2c7509ac9 100644
--- a/docs/accessibility-audit-2026-10-14.md
+++ b/docs/accessibility-audit-2026-10-14.md
@@ -374,8 +374,6 @@ What failed, and what changed:
Still open, not blocking the turn:
-- The Cabinet's two scroll bars are each one extra Tab stop.
-- A city panel button that is gone or disabled after the press (Assign's - at 0) still drops the focus.
- From a screen's button it takes about 16 Tabs to reach the screen's first control.
Pinned in EditMode: the card's order (the card, each option, Hide, the side menu, New Game, End Turn, Star, Report,
@@ -383,6 +381,26 @@ Share, the card again; Shift+Tab the reverse), End Turn's (the map stop, the min
Share, the side menu, New Game, End Turn; Shift+Tab to New Game) and where the focus goes after End Turn
(`KeyboardTurnTests`). No UI string was added, so nothing goes to #564.
+## The two scroll-bar and focus-drop fixes, 23 October 2026
+
+Two of the three items the 22 October list left open are closed here (the owner's list of 23 October 2026,
+items 1 and 2); the third, the long Tab run from a screen's button to its first control, is still open above.
+Both were found again on main `eddd66e6` before the change, and each has an EditMode test that fails without
+it.
+
+| | Finding | Fix |
+|---|---|---|
+| K3 | The Cabinet's scroll bars each take a Tab stop. Walking the screen's order shows `unity-slider`, a `ScrollerSlider` inside `cabinet-seats`, as a stop after the last seat, and the same inside `cabinet-candidates` once a seat is open. Before a seat is opened only the seat list's bar is in the order, so the default Cabinet has one stray stop and an open seat has two. | `FocusScroll.BarsAreNotTabStops` takes a view's scrollers, their sliders and their arrow buttons out of the Tab order; `CabinetPresenter` calls it for both views. Focusability only: dragging the bar and the wheel are untouched. |
+| K4 | A city panel button that the press itself leaves gone or disabled drops the focus. The Assign stepper's minus disables itself at 0 (`GddHexPanel`, `SetEnabled(target > 0)`), so after the press that reaches 0 the K2 fix hands the focus to a disabled button, `Focus()` does not take, and nothing has the focus: the next Tab starts again at Cabinet, which is the H2 symptom K2 was meant to end. Build, Stop and a project's Cancel are the same shape: Build disables every Build in the part once one group is ordered, and Stop and Cancel leave a state line and a disabled button. | `FocusReturn.ToOrWithin` focuses the rebuilt button of the same name when it can take the focus, and otherwise the nearest control that can, trying the part, then the host it was in, then the other host, and last the map stop the panel was opened from, so the next Tab carries on from where the player was. |
+
+`KeyboardTurnTests` asserted the K1 behaviour, that the Tab after the last seat lands on a scroll bar. That
+assertion is inverted with K3, since the stop is gone.
+
+Pinned in EditMode: `CabinetScrollFocusTests` (no scroll bar takes a stop in the Cabinet, with and without a
+seat open), `CityPanelFocusTests` (the Assign minus at 0 keeps the focus inside the city panel) and
+`SitePanelFocusTests` (a Build order, which disables every Build in its part, leaves the focus on something that
+can hold it). No UI string was added, so nothing goes to #564.
+
## Screenshots
In `.superpowers/a11y-2026-10-14/` (1568x752 unless noted), with the driver and the contrast, colour-vision and
diff --git a/unity/Assets/Scripts/UI/CabinetPresenter.cs b/unity/Assets/Scripts/UI/CabinetPresenter.cs
index 17dc04cb6..f948e21e9 100644
--- a/unity/Assets/Scripts/UI/CabinetPresenter.cs
+++ b/unity/Assets/Scripts/UI/CabinetPresenter.cs
@@ -46,6 +46,7 @@ namespace Statecraft.Game.UI
screen = root.Q<VisualElement>("screen-cabinet"); this.bridge = bridge; this.text = text; this.portraits = portraits;
pmCard = screen.Q<Button>("seat-" + PrimeMinister);
list = screen.Q<ScrollView>("cabinet-seats"); candidates = screen.Q<ScrollView>("cabinet-candidates");
+ FocusScroll.BarsAreNotTabStops(list, candidates); // #41: each bar was an extra Tab stop after the last row
pmOffices = screen.Q<VisualElement>("cabinet-pm-offices"); chips = screen.Q<VisualElement>("cabinet-parties");
hemicycle = screen.Q<Hemicycle>("cabinet-hemicycle");
hemicycle.Mirrored = text["ui.lang"] == UiLanguage.Hebrew; // the coalition from the right in a right-to-left UI
diff --git a/unity/Assets/Scripts/UI/FocusReturn.cs b/unity/Assets/Scripts/UI/FocusReturn.cs
index 10762dff2..7a931bf25 100644
--- a/unity/Assets/Scripts/UI/FocusReturn.cs
+++ b/unity/Assets/Scripts/UI/FocusReturn.cs
@@ -17,6 +17,31 @@ namespace Statecraft.Game.UI
target.Focus();
target.schedule.Execute(() => { if (target.panel != null && target.focusController?.focusedElement == null) target.Focus(); });
}
+
+ /// <summary>Whether an element can actually take the keyboard focus now: a control that is disabled or not drawn
+ /// cannot, and asking it to leaves the focus nowhere.</summary>
+ static bool CanTakeFocus(VisualElement? e) =>
+ e?.panel != null && e.focusable && e.enabledInHierarchy && e.resolvedStyle.display != DisplayStyle.None;
+
+ /// <summary>Focuses <paramref name="target"/>; failing that the first control that can take the focus in each of
+ /// <paramref name="scopes"/> in turn; and last of all <paramref name="last"/> (accessibility audit, #41, the
+ /// keyboard-only turn's "Still open" list). The K2 fix hands the focus to the rebuilt button of the same name, but
+ /// a press can leave its whole part with nothing focusable: Build on a site or a corridor segment disables every
+ /// Build in the part once one group is ordered, and Stop and a project's Cancel leave a state line and a disabled
+ /// button. Without a last stop outside the part the focus is left nowhere and the next Tab starts again at the
+ /// first screen, which is the symptom K2 was meant to end. Nearest first, so the next Tab stays where the player
+ /// was working.</summary>
+ public static void ToOrWithin(VisualElement? target, VisualElement? last, params VisualElement?[] scopes)
+ {
+ if (CanTakeFocus(target)) { To(target); return; }
+ foreach (var scope in scopes)
+ {
+ if (scope?.panel == null) continue;
+ foreach (var e in scope.Query<VisualElement>().Build())
+ if (e != scope && CanTakeFocus(e)) { To(e); return; }
+ }
+ if (CanTakeFocus(last)) To(last);
+ }
}
/// <summary>Whether the last press inside an element came from the keyboard (Enter or Space: NavigationSubmitEvent) or
diff --git a/unity/Assets/Scripts/UI/FocusScroll.cs b/unity/Assets/Scripts/UI/FocusScroll.cs
index 3a993ca5d..da9267403 100644
--- a/unity/Assets/Scripts/UI/FocusScroll.cs
+++ b/unity/Assets/Scripts/UI/FocusScroll.cs
@@ -86,5 +86,27 @@ namespace Statecraft.Game.UI
}
static bool LaidOut(Rect r) => !float.IsNaN(r.width) && !float.IsNaN(r.height) && r.width > 0f && r.height > 0f;
+
+ /// <summary>Takes a scroll view's own scroll bars out of the Tab order (accessibility audit, #41, the keyboard-only
+ /// turn's "Still open" list). A scroll bar is always in sight and the list it belongs to is reached by Tabbing
+ /// through its rows, so a stop on the bar only adds a press between the last row and the next control. Dragging it
+ /// with the pointer and the mouse wheel are untouched: this changes focusability, not behaviour. Call it after the
+ /// view exists; UI Toolkit rebuilds the bars' children with the view, so the sliders are set as well as the
+ /// scrollers.</summary>
+ public static void BarsAreNotTabStops(params ScrollView?[] views)
+ {
+ foreach (var view in views)
+ {
+ if (view == null) continue;
+ foreach (var scroller in new[] { view.verticalScroller, view.horizontalScroller })
+ {
+ if (scroller == null) continue;
+ scroller.focusable = false;
+ if (scroller.slider != null) scroller.slider.focusable = false;
+ if (scroller.lowButton != null) scroller.lowButton.focusable = false;
+ if (scroller.highButton != null) scroller.highButton.focusable = false;
+ }
+ }
+ }
}
}
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 7ea05f384..ce7dfa09f 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -46,6 +46,9 @@ namespace Statecraft.Game.UI
readonly VisualElement gdd;
/// <summary>The hex's city projects (GddHexPanel, #1122), under the facts.</summary>
readonly VisualElement projects;
+ /// <summary>The map stop the panel is opened from: the last place to put the focus when a press leaves its whole
+ /// part with nothing that can take it (#41, "Still open" item 2).</summary>
+ readonly VisualElement? mapFocus;
readonly IReadOnlyDictionary<string, string> settlementNames;
readonly MapRegions? regions;
readonly System.Func<string, (int q, int r)>? townHex;
@@ -87,6 +90,7 @@ namespace Statecraft.Game.UI
thumb = panel.Q<UiIcon>("info-thumb");
gdd = panel.Q<VisualElement>(GddHexPanel.HostName);
projects = panel.Q<VisualElement>(GddHexPanel.ProjectsHostName);
+ mapFocus = root.Q<VisualElement>("map-focus");
foreach (var row in panel.Query(className: RowClass).ToList()) rows.Add((row, row.Q<Label>()));
campButton = panel.Q<Button>("build-camp"); housingButton = panel.Q<Button>("build-housing");
onCamp = () => Build(MapActions.TransitCamp); onHousing = () => Build(MapActions.Housing);
@@ -470,13 +474,24 @@ namespace Statecraft.Game.UI
// names (site-build-<unit>, site-stop), so the button is looked up inside the part it was in.
var focused = presses.ByKeyboard ? panel.focusController?.focusedElement as VisualElement : null;
var keep = focused != null && (gdd.Contains(focused) || projects.Contains(focused)) ? focused.name : null;
+ // Which host it was in, read before Render while it is still in the tree: afterwards a button that is gone
+ // from gdd would look as though it had been in projects.
+ var keptIn = keep == null ? null : gdd.Contains(focused!) ? gdd : projects;
var part = keep == null ? null : focused!.parent;
while (part != null && !(part.name is { } pn && (pn.StartsWith("site-part-", System.StringComparison.Ordinal) || pn.StartsWith("corridor-part-", System.StringComparison.Ordinal))))
part = part.parent;
var partName = part?.name;
var siteName = GddHexPanel.Render(gdd, projects, bridge, text, q, r, TownName);
if (!string.IsNullOrEmpty(keep))
- FocusReturn.To(partName != null ? gdd.Q(partName)?.Q(keep) : gdd.Q(keep) ?? projects.Q(keep));
+ {
+ // The rebuilt button of the same name; failing that the nearest control that can take the focus, the
+ // part first, then the host it was in, then the other host, and last the map stop (#41, "Still open"
+ // item 2). A press can leave its whole part unfocusable: Build disables every Build in the part once one
+ // group is ordered, and Stop and a project's Cancel leave a state line and a disabled button.
+ var rebuiltPart = partName != null ? gdd.Q(partName) : null;
+ var again = rebuiltPart != null ? rebuiltPart.Q(keep) : keptIn!.Q(keep);
+ FocusReturn.ToOrWithin(again, mapFocus, rebuiltPart, keptIn, keptIn == gdd ? projects : gdd);
+ }
if (siteName != null && owned.Count == 0) title.text = siteName;
subtitle.text = hex == null ? "" : text.Format("info.hex", text["info.biome." + hex.Biome], hex.ElevM); // no debug coordinates in player text (playtest 2, P2-6)
// The armistice zone in force, else the sub-district on 15 May 1948, and any armistice line in force through the
diff --git a/unity/Assets/Tests/EditMode/A11yKeyboardShots.cs b/unity/Assets/Tests/EditMode/A11yKeyboardShots.cs
new file mode 100644
index 000000000..3fb49f9a8
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/A11yKeyboardShots.cs
@@ -0,0 +1,189 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>Writes the before and after stills for #41's "Still open" items 1 and 2, in English and Hebrew, to
+/// `.superpowers/a11y-keyboard-41/` as the 14 October audit does (local, not committed). Both "before" states are the old
+/// code paths called directly rather than a mock: item 1 puts the scrollers back in the Tab order, which is what they were
+/// before `BarsAreNotTabStops`; item 2 calls `FocusReturn.To` on the button the press disabled, which is what
+/// `InfoPanelPresenter` did before `ToOrWithin`. Explicit so this does not run in CI with the rest.</summary>
+[Explicit("writes stills for a pull request, not a check")]
+public class A11yKeyboardShots
+{
+ string saveDir = "";
+ string shotDir = "";
+ RenderTexture? rt; PanelSettings? ps;
+ VisualElement ui = null!;
+ GameRoot root = null!;
+
+ [SetUp]
+ public void TempSaves()
+ {
+ saveDir = Path.Combine(Path.GetTempPath(), "statecraft-shots-" + Guid.NewGuid().ToString("N"));
+ shotDir = Path.Combine(Directory.GetCurrentDirectory(), ".superpowers", "a11y-keyboard-41");
+ Directory.CreateDirectory(shotDir);
+ }
+
+ [TearDown]
+ public void DiscardScene()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (ps != null) Object.DestroyImmediate(ps);
+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }
+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ }
+
+ SimBridge Bridge => root.Bridge!;
+ Focusable? Focused => ui.panel?.focusController?.focusedElement;
+ VisualElement At => Focused as VisualElement ?? throw new AssertionException("nothing has the focus");
+ string FocusedName => (Focused as VisualElement)?.name is string n && n.Length > 0 ? n : Focused == null ? "none" : Focused.GetType().Name;
+
+ IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }
+
+ IEnumerator Tab(bool back = false)
+ {
+ var at = At;
+ using (var e = NavigationMoveEvent.GetPooled(back ? NavigationMoveEvent.Direction.Previous : NavigationMoveEvent.Direction.Next)) { e.target = at; at.SendEvent(e); }
+ yield return null;
+ }
+
+ IEnumerator Enter()
+ {
+ var at = At;
+ using (var k = KeyDownEvent.GetPooled('\n', KeyCode.Return, EventModifiers.None)) { k.target = at; at.SendEvent(k); }
+ using (var s = NavigationSubmitEvent.GetPooled()) { s.target = at; at.SendEvent(s); }
+ yield return null;
+ }
+
+ IEnumerator Boot(bool hebrew)
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ rt = new RenderTexture(1280, 720, 24);
+ ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
+ root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ if (hebrew) root.Language = UiLanguage.Hebrew;
+ root.Begin(MapFocusTests.Inputs, 0);
+ ui = doc.rootVisualElement;
+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;
+ yield return Frames(5);
+ }
+
+ void Shot(string name)
+ {
+ var prev = RenderTexture.active;
+ RenderTexture.active = rt;
+ var tex = new Texture2D(rt!.width, rt.height, TextureFormat.RGB24, false);
+ tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
+ tex.Apply();
+ RenderTexture.active = prev;
+ File.WriteAllBytes(Path.Combine(shotDir, name + ".png"), tex.EncodeToPNG());
+ Object.DestroyImmediate(tex);
+ Debug.Log($"SHOT {name}: focus is on {FocusedName}");
+ }
+
+ static void PutScrollBarsBackInTheOrder(params ScrollView?[] views)
+ {
+ foreach (var v in views)
+ {
+ if (v == null) continue;
+ foreach (var s in new[] { v.verticalScroller, v.horizontalScroller })
+ {
+ if (s == null) continue;
+ s.focusable = true;
+ if (s.slider != null) s.slider.focusable = true;
+ }
+ }
+ }
+
+ IEnumerator Shots(bool hebrew)
+ {
+ var lang = hebrew ? "he" : "en";
+ yield return Boot(hebrew);
+ Bridge.State.Attention = 100;
+ GameSceneTests.HideTheOpeningCard(ui);
+ yield return Frames(3);
+
+ // ---- item 1: the Cabinet's scroll bars ----
+ var nav = ui.Q<Button>("nav-cabinet");
+ nav.Focus(); yield return null;
+ yield return Enter();
+ yield return Frames(5);
+
+ var seats = ui.Q<ScrollView>("cabinet-seats");
+ var cands = ui.Q<ScrollView>("cabinet-candidates");
+
+ // before: the scrollers back in the order, Tab from the last seat lands on the bar
+ PutScrollBarsBackInTheOrder(seats, cands);
+ var last = ui.Q<Button>("seat-chief_of_staff");
+ if (last != null) { last.Focus(); yield return null; yield return Tab(); yield return Frames(2); }
+ Shot($"item1-before-{lang}");
+
+ // after: the fix as it ships; the same Tab goes on to the next control
+ FocusScroll.BarsAreNotTabStops(seats, cands);
+ if (last != null) { last.Focus(); yield return null; yield return Tab(); yield return Frames(2); }
+ Shot($"item1-after-{lang}");
+
+ // ---- item 2: the city panel's Assign minus at 0 ----
+ ui.Q<Button>("screen-close-cabinet")?.Focus(); yield return null;
+ yield return Enter();
+ yield return Frames(3);
+ LookAtTelAviv();
+ var stop = ui.Q("map-focus");
+ for (int i = 0; i < 10 && Focused != stop; i++) { yield return null; stop.Focus(); }
+ yield return Enter();
+ yield return Frames(3);
+ Bridge.State.Attention = 100;
+ Bridge.Queue(new AssignWorkers("tel_aviv", "job", 1));
+ yield return Frames(5);
+
+ var less = ui.Q<Button>("city-workers-less");
+ if (less != null)
+ {
+ less.Focus(); yield return null;
+ yield return Enter(); // reaches 0; the button disables itself
+ yield return Frames(5);
+ Shot($"item2-after-{lang}"); // the fix: the focus stays in the panel
+
+ // before: what InfoPanelPresenter did, FocusReturn.To onto the disabled button
+ var dead = ui.Q<Button>("city-workers-less");
+ ui.panel?.focusController?.focusedElement?.Blur();
+ yield return null;
+ FocusReturn.To(dead);
+ yield return Frames(3);
+ Shot($"item2-before-{lang}");
+ }
+ }
+
+ static void LookAtTelAviv()
+ {
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var c = MapFocusTests.Inputs.Content;
+ var tlv = c.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ var hex = c.HexAt(tlv.Q, tlv.R)!;
+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ ground.y = map.Terrain.SampleHeight(ground) + map.Terrain.transform.position.y;
+ var rig = Camera.main.GetComponent<CameraRig>();
+ rig.LookAt = ground; rig.Distance = 30000f;
+ rig.Apply();
+ }
+
+ [UnityTest] public IEnumerator English() { yield return Shots(false); }
+ [UnityTest] public IEnumerator Hebrew() { yield return Shots(true); }
+}
diff --git a/unity/Assets/Tests/EditMode/A11yKeyboardShots.cs.meta b/unity/Assets/Tests/EditMode/A11yKeyboardShots.cs.meta
new file mode 100644
index 000000000..28e242775
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/A11yKeyboardShots.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: fbd43a8ea3fb34307b12ddff5382e97a
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/CabinetScrollFocusTests.cs b/unity/Assets/Tests/EditMode/CabinetScrollFocusTests.cs
new file mode 100644
index 000000000..34a5c32d0
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/CabinetScrollFocusTests.cs
@@ -0,0 +1,141 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>#41, the keyboard-only turn's "Still open" list (owner, 23 October 2026), item 1: the Cabinet's two scroll
+/// bars are each an extra Tab stop. A ScrollView's scroller is always in sight and cannot be operated usefully from the
+/// keyboard here, so it should not take a Tab stop at all. Same harness as KeyboardTurnTests: Map.unity at 1280x720, a
+/// new GDD game, keys sent as the UI Toolkit events the Input System's UI provider makes of them.</summary>
+public class CabinetScrollFocusTests
+{
+ string saveDir = "";
+ RenderTexture? rt; PanelSettings? ps;
+ VisualElement ui = null!;
+ GameRoot root = null!;
+
+ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-kbscroll-" + Guid.NewGuid().ToString("N"));
+
+ [TearDown]
+ public void DiscardScene()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (ps != null) Object.DestroyImmediate(ps);
+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }
+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ }
+
+ SimBridge Bridge => root.Bridge!;
+ Focusable? Focused => ui.panel?.focusController?.focusedElement;
+ VisualElement At => Focused as VisualElement ?? throw new AssertionException("nothing has the focus");
+ string FocusedName => (Focused as VisualElement)?.name is string n && n.Length > 0 ? n : Focused == null ? "none" : Focused.GetType().Name;
+
+ /// <summary>The scroll view an element sits inside, if any: that is what makes a stop a scroll-bar stop rather than a
+ /// control the player meant to reach.</summary>
+ static string? ScrollViewAbove(Focusable? f)
+ {
+ for (var p = f as VisualElement; p != null; p = p.parent)
+ if (p is ScrollView sv) return sv.name is string n && n.Length > 0 ? n : "(unnamed ScrollView)";
+ return null;
+ }
+
+ static bool IsScrollBarStop(Focusable? f) =>
+ f is Scroller || f is Slider || (f as VisualElement)?.GetType().Name is "ScrollerSlider";
+
+ IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }
+
+ IEnumerator Tab(bool back = false)
+ {
+ var at = At;
+ using (var e = NavigationMoveEvent.GetPooled(back ? NavigationMoveEvent.Direction.Previous : NavigationMoveEvent.Direction.Next)) { e.target = at; at.SendEvent(e); }
+ yield return null;
+ }
+
+ IEnumerator Enter()
+ {
+ var at = At;
+ using (var k = KeyDownEvent.GetPooled('\n', KeyCode.Return, EventModifiers.None)) { k.target = at; at.SendEvent(k); }
+ using (var s = NavigationSubmitEvent.GetPooled()) { s.target = at; at.SendEvent(s); }
+ yield return null;
+ }
+
+ IEnumerator Boot()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ rt = new RenderTexture(1280, 720, 0);
+ ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
+ root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Begin(MapFocusTests.Inputs, 0);
+ ui = doc.rootVisualElement;
+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;
+ yield return Frames(5);
+ Assert.IsTrue(Bridge.Content.IsGdd, "precondition: the GDD loop");
+ }
+
+ /// <summary>Answers the opening card and opens the Cabinet from the keyboard, as the keyboard-only turn does.</summary>
+ IEnumerator OpenCabinet()
+ {
+ yield return Boot();
+ yield return Tab();
+ yield return Enter();
+ yield return Frames(3);
+ for (int i = 0; i < 30 && FocusedName != "nav-cabinet"; i++) yield return Tab();
+ Assert.AreEqual("nav-cabinet", FocusedName, "precondition: reached the Cabinet button");
+ yield return Enter();
+ yield return Frames(5);
+ }
+
+ /// <summary>Tabs a whole lap and returns every stop that sits inside a ScrollView and is a scroll bar.</summary>
+ IEnumerator ScrollBarStops(List<string> into, int laps = 60)
+ {
+ for (int i = 0; i < laps; i++)
+ {
+ if (IsScrollBarStop(Focused))
+ into.Add($"{FocusedName} in {ScrollViewAbove(Focused) ?? "(no ScrollView)"}");
+ yield return Tab();
+ }
+ }
+
+ [UnityTest]
+ public IEnumerator TheCabinetsSeatListScrollBarIsNotATabStop()
+ {
+ yield return OpenCabinet();
+ var stops = new List<string>();
+ yield return ScrollBarStops(stops);
+ CollectionAssert.IsEmpty(stops, "a scroll bar took a Tab stop in the Cabinet: " + string.Join(", ", stops));
+ }
+
+ [UnityTest]
+ public IEnumerator TheCabinetsCandidateListScrollBarIsNotATabStop()
+ {
+ yield return OpenCabinet();
+ // open a seat so the candidate list renders; its scroll bar is only in the order once it is shown
+ for (int i = 0; i < 40 && !FocusedName.StartsWith("seat-"); i++) yield return Tab();
+ Assert.IsTrue(FocusedName.StartsWith("seat-"), "precondition: reached a minister's seat");
+ yield return Enter();
+ yield return Frames(5);
+ Assert.IsTrue(ui.Q<ScrollView>("cabinet-candidates")?.resolvedStyle.display == DisplayStyle.Flex,
+ "precondition: the candidate list is shown");
+
+ var stops = new List<string>();
+ yield return ScrollBarStops(stops);
+ CollectionAssert.IsEmpty(stops, "a scroll bar took a Tab stop with the candidate list open: " + string.Join(", ", stops));
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/CabinetScrollFocusTests.cs.meta b/unity/Assets/Tests/EditMode/CabinetScrollFocusTests.cs.meta
new file mode 100644
index 000000000..856f1708d
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/CabinetScrollFocusTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: baf3dc4178979427883904ca3a325933
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/CityPanelFocusTests.cs b/unity/Assets/Tests/EditMode/CityPanelFocusTests.cs
new file mode 100644
index 000000000..45a59a3d6
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/CityPanelFocusTests.cs
@@ -0,0 +1,148 @@
+#nullable enable
+using System;
+using System.Collections;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor.SceneManagement;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UIElements;
+using Object = UnityEngine.Object;
+
+/// <summary>#41, the keyboard-only turn's "Still open" list (owner, 23 October 2026), item 2: a city panel button that is
+/// gone or disabled after the press still drops the focus. #1330's K2 fix gives the focus to the rebuilt button of the
+/// same name, but the Assign stepper's minus disables itself at 0 (`GddHexPanel`, "city-workers-less",
+/// SetEnabled(target > 0)), so after the press that reaches 0 there is no button able to take it and the focus is lost:
+/// the next Tab starts again at Cabinet, which is the H2 symptom K2 was meant to end. Same harness as
+/// KeyboardTurnTests.</summary>
+public class CityPanelFocusTests
+{
+ string saveDir = "";
+ RenderTexture? rt; PanelSettings? ps;
+ VisualElement ui = null!;
+ GameRoot root = null!;
+
+ [SetUp] public void TempSaves() => saveDir = Path.Combine(Path.GetTempPath(), "statecraft-citypanel-" + Guid.NewGuid().ToString("N"));
+
+ [TearDown]
+ public void DiscardScene()
+ {
+ EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
+ if (ps != null) Object.DestroyImmediate(ps);
+ if (rt != null) { rt.Release(); Object.DestroyImmediate(rt); }
+ if (Directory.Exists(saveDir)) Directory.Delete(saveDir, true);
+ }
+
+ SimBridge Bridge => root.Bridge!;
+ Focusable? Focused => ui.panel?.focusController?.focusedElement;
+ VisualElement At => Focused as VisualElement ?? throw new AssertionException("nothing has the focus");
+ string FocusedName => (Focused as VisualElement)?.name is string n && n.Length > 0 ? n : Focused == null ? "none" : Focused.GetType().Name;
+
+ IEnumerator Frames(int n) { for (int i = 0; i < n; i++) yield return null; }
+
+ IEnumerator Tab(bool back = false)
+ {
+ var at = At;
+ using (var e = NavigationMoveEvent.GetPooled(back ? NavigationMoveEvent.Direction.Previous : NavigationMoveEvent.Direction.Next)) { e.target = at; at.SendEvent(e); }
+ yield return null;
+ }
+
+ IEnumerator Enter()
+ {
+ var at = At;
+ using (var k = KeyDownEvent.GetPooled('\n', KeyCode.Return, EventModifiers.None)) { k.target = at; at.SendEvent(k); }
+ using (var s = NavigationSubmitEvent.GetPooled()) { s.target = at; at.SendEvent(s); }
+ yield return null;
+ }
+
+ IEnumerator TabTo(string name, int max = 80)
+ {
+ for (int i = 0; i < max && FocusedName != name; i++) yield return Tab();
+ Assert.AreEqual(name, FocusedName, $"Tabbed to {name}");
+ }
+
+ IEnumerator Boot()
+ {
+ EditorSceneManager.OpenScene("Assets/Map.unity", OpenSceneMode.Single);
+ var doc = Object.FindFirstObjectByType<UIDocument>();
+ rt = new RenderTexture(1280, 720, 0);
+ ps = Object.Instantiate(doc.panelSettings);
+ ps.targetTexture = rt;
+ doc.panelSettings = ps;
+ Object.FindFirstObjectByType<MapScene>().Build(MapFocusTests.Inputs.Map);
+ root = Object.FindFirstObjectByType<GameRoot>();
+ root.Store = new SaveStore(saveDir);
+ root.Begin(MapFocusTests.Inputs, 0);
+ ui = doc.rootVisualElement;
+ for (int i = 0; i < 30 && !(ui.Q("top-bar").worldBound.height > 0); i++) yield return null;
+ yield return Frames(5);
+ Assert.IsTrue(Bridge.Content.IsGdd, "precondition: the GDD loop");
+ }
+
+ static void LookAtTelAviv()
+ {
+ var map = Object.FindFirstObjectByType<MapScene>();
+ var c = MapFocusTests.Inputs.Content;
+ var tlv = c.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ var hex = c.HexAt(tlv.Q, tlv.R)!;
+ var ground = map.Frame.ToWorld(hex.Lon, hex.Lat, 0);
+ ground.y = map.Terrain.SampleHeight(ground) + map.Terrain.transform.position.y;
+ var rig = Camera.main.GetComponent<CameraRig>();
+ rig.LookAt = ground; rig.Distance = 30000f;
+ rig.Apply();
+ }
+
+ /// <summary>Opens Tel Aviv's city panel, as ATrainingOrderByThePointerLeavesNoFocus does. The attention is raised for
+ /// the same reason KeyboardTurnTests raises it: what is checked here is the keyboard's path, not the attention rule,
+ /// and the opening turn's 4 attention does not pay for stepping the Assign count down to zero.</summary>
+ IEnumerator OpenTelAviv()
+ {
+ yield return Boot();
+ Bridge.State.Attention = 100;
+ GameSceneTests.HideTheOpeningCard(ui);
+ LookAtTelAviv();
+ var stop = ui.Q("map-focus");
+ for (int i = 0; i < 10 && Focused != stop; i++) { yield return null; stop.Focus(); }
+ yield return Enter();
+ Assert.AreEqual("Tel Aviv", ui.Q<Label>("info-title").text, "precondition: Tel Aviv's city panel");
+ }
+
+ [UnityTest]
+ public IEnumerator TheAssignMinusKeepsTheFocusWhenItDisablesItselfAtZero()
+ {
+ yield return OpenTelAviv();
+
+ var less = ui.Q<Button>("city-workers-less");
+ Assert.IsNotNull(less, "precondition: the Assign stepper's minus is in the panel");
+ Assert.IsTrue(less.enabledSelf, "precondition: it starts enabled, so some workers are assigned");
+
+ // Tel Aviv starts with 86 groups in work, so stepping down one press at a time would take 86 presses. Order one
+ // group directly, which is what the stepper itself queues, so a single press then reaches 0 and disables the
+ // button. That is the press this test is about.
+ Bridge.Queue(new AssignWorkers("tel_aviv", "job", 1));
+ yield return Frames(5);
+ var one = ui.Q<Button>("city-workers-less");
+ Assert.IsNotNull(one, "precondition: the minus is still in the panel at 1");
+ Assert.IsTrue(one.enabledSelf, $"precondition: the minus is enabled at 1; the count reads {ui.Q<Label>("city-workers")?.text}");
+ one.Focus();
+ yield return null;
+ Assert.AreEqual("city-workers-less", FocusedName, "precondition: the minus has the focus before the press");
+
+ yield return Enter();
+ yield return Frames(5);
+
+ var after = ui.Q<Button>("city-workers-less");
+ Assert.IsTrue(after == null || !after.enabledSelf,
+ $"precondition: the minus is gone or disabled after the press that reaches 0, but it is still enabled; the count reads {ui.Q<Label>("city-workers")?.text}");
+
+ Assert.IsNotNull(Focused, "the focus is not dropped when the pressed button cannot take it back");
+ Assert.IsTrue(ui.Q("info-panel")?.Contains(At) ?? false,
+ $"the focus stays in the city panel, but it is on {FocusedName}");
+ Assert.AreEqual("city-workers-more", FocusedName, "and on the stepper's plus, the nearest control that can take it");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/CityPanelFocusTests.cs.meta b/unity/Assets/Tests/EditMode/CityPanelFocusTests.cs.meta
new file mode 100644
index 000000000..f143e15ff
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/CityPanelFocusTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 0285735185733495eaec9cdbd6b9fb93
\ No newline at end of file
diff --git a/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs b/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs
index 46301c186..62cbc42bc 100644
--- a/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs
+++ b/unity/Assets/Tests/EditMode/KeyboardTurnTests.cs
@@ -202,10 +202,12 @@ public class KeyboardTurnTests
yield return TabTo(v => ui.Q("cabinet-candidates").Contains(v), "a candidate");
yield return Enter();
Assert.IsTrue(Bridge.Queued.OfType<Appoint>().Any(), "the appointment is ordered");
- // The candidate list's and the seat list's own scroll bars take Tab after their last row: no error, and Tab goes on.
+ // The lists' own scroll bars used to take Tab after their last row (K1). They are out of the order now
+ // (#41, "Still open" item 1), so the Tab after the last seat leaves the screen for the HUD's Cabinet button,
+ // the next control in the order, instead of stopping on a bar that cannot be used from the keyboard.
yield return TabTo(v => v.name == "seat-chief_of_staff", "the last seat, past every candidate", 120);
yield return Tab();
- Assert.IsTrue(At is Scroller || At.GetFirstAncestorOfType<Scroller>() != null, $"the Tab after the last seat lands on a scroll bar (K1), not {FocusedName}");
+ Assert.AreEqual("nav-cabinet", FocusedName, "the Tab after the last seat goes on to the HUD, not to a scroll bar");
yield return TabTo("nav-cabinet");
yield return Escape();
Assert.IsNull(ScreenOpen(), "Escape closes the Cabinet");
diff --git a/unity/Assets/Tests/EditMode/SitePanelFocusTests.cs b/unity/Assets/Tests/EditMode/SitePanelFocusTests.cs
new file mode 100644
index 000000000..0b00e5865
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/SitePanelFocusTests.cs
@@ -0,0 +1,72 @@
+#nullable enable
+using System;
+using System.IO;
+using System.Linq;
+using NUnit.Framework;
+using Statecraft.Game;
+using Statecraft.Game.Map;
+using Statecraft.Game.UI;
+using Statecraft.Sim;
+using UnityEditor;
+using UnityEngine;
+using UnityEngine.UIElements;
+
+/// <summary>#41, the keyboard-only turn's "Still open" list, item 2, the case where the press leaves its whole part with
+/// nothing that can take the focus. One Build order on a site sets `taken`, which disables every Build in that part
+/// (`GddHexPanel`, `SetEnabled(!ordered &amp;&amp; !taken)`), so the part is then a state line and disabled buttons. Stop on a
+/// site or a corridor segment and a project's Cancel have the same shape. Without a last stop outside the part the focus
+/// is left nowhere and the next Tab starts again at the first screen. Harness as `CityPanelTests`: `UiTestKit` gives the
+/// tree a real panel, so focus and Submit both work.</summary>
+public class SitePanelFocusTests
+{
+ static readonly Content C = ContentLoader.Load(Paths.Content);
+ static readonly System.Collections.Generic.List<Settlement> Towns =
+ SettlementPlacer.Parse(File.ReadAllText(Path.Combine(Paths.Content, "map", SettlementPlacer.DefaultFileName)));
+ static UiText En => UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.Strings).text);
+ const string City = "tel_aviv", Site = "mefalsim";
+
+ static (int q, int r) CityHex => C.SettlementHexes.Where(x => x.Id == City).Select(x => (x.Q, x.R)).Single();
+ static Statecraft.Sim.Site SiteDef => C.Sites.Single(x => x.Id == Site);
+
+ static SimBridge Bridge(UiText text, Action<GameState>? edit = null)
+ {
+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ edit?.Invoke(g.State);
+ return new SimBridge(g, text);
+ }
+
+ static InfoPanelPresenter Panel(UiTestKit ui, SimBridge bridge, UiText text) =>
+ new InfoPanelPresenter(ui.Root, bridge, text, Towns.ToDictionary(t => t.Id, t => t.Name));
+
+ static int AddHalutz(GameState s)
+ {
+ var id = s.NextId++;
+ s.Units.Add(id, new Unit(id, "halutz", CityHex.q, CityHex.r));
+ return id;
+ }
+
+ [Test]
+ public void BuildKeepsTheFocusWhenItDisablesEveryBuildInThePart()
+ {
+ using var ui = new UiTestKit();
+ int a = -1, b = -1;
+ var bridge = Bridge(En, s => { a = AddHalutz(s); b = AddHalutz(s); });
+ using var panel = Panel(ui, bridge, En);
+ panel.Show(SiteDef.Q, SiteDef.R);
+
+ var first = ui.Q<Button>($"site-build-{a}");
+ Assert.IsTrue(first.enabledSelf, "precondition: Build is enabled before the order");
+ first.Focus();
+ Assert.AreEqual(first, ui.Root.panel.focusController.focusedElement, "precondition: Build has the focus");
+
+ UiTestKit.Press(first);
+
+ // One order takes the site, so every Build in the part is disabled and nothing in it can hold the focus.
+ Assert.IsFalse(ui.Root.Q<Button>($"site-build-{a}")?.enabledSelf ?? false, "precondition: the pressed Build is disabled");
+ Assert.IsFalse(ui.Root.Q<Button>($"site-build-{b}")?.enabledSelf ?? false, "precondition: the other group's Build is disabled too");
+
+ var now = ui.Root.panel.focusController.focusedElement as VisualElement;
+ Assert.IsNotNull(now, "the focus is not dropped when the whole part is disabled");
+ Assert.IsTrue(now!.enabledInHierarchy && now.focusable, $"and it is on something that can hold it, not {now.name}");
+ }
+}
diff --git a/unity/Assets/Tests/EditMode/SitePanelFocusTests.cs.meta b/unity/Assets/Tests/EditMode/SitePanelFocusTests.cs.meta
new file mode 100644
index 000000000..9a3deb0f4
--- /dev/null
+++ b/unity/Assets/Tests/EditMode/SitePanelFocusTests.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 2883612e3914e427b86c4344524206b4
\ No newline at end of file