Hand focus to a rail entry when a panel folds it away

- When F or a panel's collapse button folds a panel that holds the focus,
  the focus moves to that panel's visible rail entry. The same happens when
  opening Data Layers folds a peer panel that held it, and in Cockpit the
  focus moves to Contact's expand button when that card folds.
- The `shownBy: 'active'` rail gate is gone: nothing removes `.active` from
  Data Layers any more, so a rail entry now follows `panel.hidden`.
- CURRENT-STATE says what F does, and the panel catalog comment no longer
  says F toggles `.active`.
This commit is contained in:
German Khokhlov committed 2026-11-19 15:00:17 +04:00
1 parent 3a24768a2d
commit c7df3c6798
9 files changed
+179 -40

No files matched your search

+5 -2
View File
@@ -1,4 +1,7 @@
- `F` now collapses and reopens the Data Layers panel the way the panel's own
button does, and its rail entry stays. Before, `F` hid the panel together
with its rail entry, so only another `F` brought it back (asturksever,
#1598).
with its rail entry, so only another `F` brought it back. When `F` or a
panel's collapse button hides a panel that holds the focus, including one
the opened panel folds away, the focus moves to that panel's rail entry;
in Cockpit, focus in the Contact card it folds moves to the card's expand
button (asturksever, #1598).
+4 -1
View File
@@ -3252,7 +3252,10 @@ Browser acceptance: `QA_BASE_URL=http://127.0.0.1:4173 node scripts/qa-segmented
`ui/input` supplies the bubbling application shortcut listener and generated
shader-parameter rows. Number/style keys, H/O/V/F/D/C actions, native form-control
typing and Escape behavior retain their existing mappings. A shortcut key held
typing and Escape behavior retain their existing mappings. `F` collapses and
reopens Data Layers the way the panel's own collapse button does, so its rail
entry stays; if focus was inside the panel, it moves to that rail entry.
A shortcut key held
with Cmd, Ctrl or Alt runs no shortcut, so the browser's own chord (Cmd+C to
copy, Cmd+F to find, Cmd+1 to switch tab) does not also toggle CCTV, the layers
panel or a style; Shift does not count, and Escape dismisses search either way.
+1 -1
View File
@@ -110,7 +110,7 @@ function harness({ hidden = false, selected = true, noChips = false } = {}) {
window.performance = { now: () => now };
document.defaultView = window;
const methods = new Function('createHoverDisclosure', 'collapsePanelOnEscape', 'document', 'window', 'clearTimeout', 'performance', 'requestAnimationFrame', 't', 'msg', 'readPanelState',
`return ({${shellMethod('_initAutoHoverPanel').toString()},\n${shellMethod('_collapsePanelOnEscape').toString()},\n${shellMethod('setPanelCollapsed').toString()},\n${shellMethod('_presentPanel').toString()},\n${shellMethod('_shownPanel').toString()}});`)(
`return ({${shellMethod('_initAutoHoverPanel').toString()},\n${shellMethod('_collapsePanelOnEscape').toString()},\n${shellMethod('_railFocusStand').toString()},\n${shellMethod('setPanelCollapsed').toString()},\n${shellMethod('_presentPanel').toString()},\n${shellMethod('_shownPanel').toString()}});`)(
createHoverDisclosure, collapsePanelOnEscape, document, window, (id) => timers.delete(id), { now: () => now }, () => {}, t, msg, readPanelState,
);
const saves = [];
+1 -1
View File
@@ -42,7 +42,7 @@ function panelFixture({ id = 'data-panel', nested = false, nestedCollapsed = fal
disclosure.closest = () => panel;
}
const document = { getElementById: (candidate) => candidate === id ? panel : null };
const manager = new Function('document', 'getComputedStyle', 'collapsePanelOnEscape', `return {${method('_collapsePanelOnEscape', '_togglePanel')}};`)(document, (el) => ({ visibility: el.visibility ?? 'visible' }), collapsePanelOnEscape);
const manager = new Function('document', 'getComputedStyle', 'collapsePanelOnEscape', `return {${method('_collapsePanelOnEscape', '_togglePanel')}, ${method('_railFocusStand', '_setCommandDockPanelPinState')}};`)(document, (el) => ({ visibility: el.visibility ?? 'visible' }), collapsePanelOnEscape);
manager.setPanelCollapsed = (candidate, value, options) => {
assert.equal(candidate, id);
assert.equal(value, true);
+41 -16
View File
@@ -204,22 +204,7 @@ export class PanelChrome {
beforeCollapse: () => {
if (panelId === 'location-bar') this._closeLocationSearch?.();
},
// A desktop side panel hides entirely once collapsed; its rail item
// takes the focus its own disclosure can no longer hold.
returnFocusTo: () => {
const panel = document.getElementById(panelId);
if (!panel?.getClientRects || panel.getClientRects().length > 0)
return null;
const item = document.querySelector?.(
`.ui-rail [data-rail-item="${panelId}"]`,
);
return item &&
!item.disabled &&
item.getClientRects().length > 0 &&
getComputedStyle(item).visibility === 'visible'
? item
: null;
},
returnFocusTo: () => this._railFocusStand(panelId),
});
}
@@ -228,9 +213,49 @@ export class PanelChrome {
if (this._disposed || !this._disclosurePanelIds?.has(panelId)) return;
const panel = document.getElementById(panelId);
if (!panel) return;
// Opening a panel folds others too (the side accordion, Cockpit's
// Contact card): note which open ones hold the focus.
const focused = document.activeElement;
const holders = [...this._disclosurePanelIds]
.map((id) => document.getElementById(id))
.filter((el) => el?.contains(focused) && !this._shownPanel(el).collapsed);
const cockpit = this.cockpitView;
const contactHeld =
cockpit?.active &&
!cockpit.contextCollapsed &&
document.getElementById('cockpit-context')?.contains(focused);
this.setPanelCollapsed(panelId, !this._shownPanel(panel).collapsed, {
explicit: true,
});
const stand =
contactHeld && cockpit.contextCollapsed
? document.getElementById('cockpit-context-toggle')
: holders
.filter((el) => this._shownPanel(el).collapsed)
.map((el) => this._railFocusStand(el.id))
.find(Boolean);
stand?.focus({ preventScroll: true });
}
/**
* A desktop side panel hides entirely once collapsed; its rail item takes
* the focus its own disclosure can no longer hold. Null while the panel or
* the item is not shown.
* @param {string} panelId Panel element id.
*/
_railFocusStand(panelId) {
const panel = document.getElementById(panelId);
if (!panel?.getClientRects || panel.getClientRects().length > 0)
return null;
const item = document.querySelector?.(
`.ui-rail [data-rail-item="${panelId}"]`,
);
return item &&
!item.disabled &&
item.getClientRects().length > 0 &&
getComputedStyle(item).visibility === 'visible'
? item
: null;
}
_setCommandDockPanelPinState(
+120 -2
View File
@@ -467,8 +467,13 @@ test('the accordion closes peers through the real store, and opens them again',
test('F collapses Data Layers like its button and keeps its rail entry', (t) => {
document.body.innerHTML = `
<nav class="ui-rail"><button data-rail-item="data-panel" style="visibility: visible"></button></nav>
<div id="data-panel" class="active"><button class="panel-collapse-btn" data-collapse-target="data-panel"></button></div>`;
const panel = document.getElementById('data-panel');
const item = document.querySelector('[data-rail-item="data-panel"]');
panel.getClientRects = () =>
panel.classList.contains('collapsed') ? [] : [{}];
item.getClientRects = () => [{}];
const store = usePanelChromeStore(createPinia());
const chrome = panelChrome(store);
followPanelState(store, 'data-panel', panel);
@@ -491,14 +496,16 @@ test('F collapses Data Layers like its button and keeps its rail entry', (t) =>
chrome.destroy();
});
const press = (init = {}) =>
document.body.dispatchEvent(
document.activeElement.dispatchEvent(
new KeyboardEvent('keydown', { key: 'f', bubbles: true, ...init }),
);
panel.querySelector('button').focus();
press();
assert.equal(store.panels['data-panel']?.collapsed, true);
assert.ok(document.activeElement === item, 'focus moves to the rail');
assert.ok(panel.classList.contains('collapsed'));
// `active` is what keeps Data Layers in the rail.
// `active` is what shows Data Layers at all (layers.css).
assert.ok(panel.classList.contains('active'));
press({ metaKey: true });
assert.equal(store.panels['data-panel'].collapsed, true, 'Cmd+F is not ours');
@@ -507,3 +514,114 @@ test('F collapses Data Layers like its button and keeps its rail entry', (t) =>
assert.ok(!panel.classList.contains('collapsed'));
assert.ok(panel.classList.contains('active'));
});
test('F that folds a focused peer hands the focus to a rail entry', (t) => {
document.body.innerHTML = `
<nav class="ui-rail">
<button data-rail-item="data-panel" style="visibility: visible"></button>
<button data-rail-item="pp-toggles" style="visibility: visible"></button>
</nav>
<div id="left-panel-stack">
<div id="data-panel" data-panel-id="data-panel" class="active collapsed"><button class="panel-collapse-btn" data-collapse-target="data-panel"></button></div>
<div id="pp-toggles" data-panel-id="pp-toggles"><button class="panel-collapse-btn" data-collapse-target="pp-toggles"></button><button id="crt2">CRT 2</button></div>
</div>`;
const stack = document.getElementById('left-panel-stack');
const store = usePanelChromeStore(createPinia());
const chrome = new PanelChrome({
elements: { _leftPanelStack: stack },
operations: { _showToast() {}, _syncCctvPanelViewport() {} },
readHud: () => ({ visible: false, getVariant: () => null }),
readCockpit: () => null,
readShareLinks: () => null,
readInitialShare: () => null,
readScrollRestoreOwner: () => null,
readDisplayScrollTop: () => 0,
store,
});
for (const id of ['data-panel', 'pp-toggles']) {
const panel = document.getElementById(id);
panel.getClientRects = () =>
panel.classList.contains('collapsed') ? [] : [{}];
followPanelState(store, id, panel);
}
for (const item of document.querySelectorAll('[data-rail-item]'))
item.getClientRects = () => [{}];
chrome._disclosurePanelIds = new Set(['data-panel', 'pp-toggles']);
const bindings = new DisplayBindings({
viewer: null,
services: { isScopeMaskEnabled: () => false, cycleDetectionMode() {} },
elements: { _locationSearch: document.createElement('input') },
operations: {
_setScope() {},
_togglePanel: (panelId) => chrome._togglePanel(panelId),
},
readState: () => ({}),
claimDetection() {},
displayStore: useDisplayStore(createPinia()),
});
bindings._initUI();
t.after(() => {
bindings.destroy();
chrome.destroy();
});
const crt2 = document.getElementById('crt2');
crt2.focus();
assert.equal(document.activeElement, crt2);
crt2.dispatchEvent(new KeyboardEvent('keydown', { key: 'f', bubbles: true }));
assert.equal(
store.panels['data-panel']?.collapsed,
false,
'Data Layers opens',
);
const visual = document.getElementById('pp-toggles');
assert.ok(
visual.classList.contains('collapsed'),
'the accordion folds Visual',
);
assert.ok(
document.activeElement?.matches?.('.ui-rail [data-rail-item]'),
`focus lands on a rail entry, not inside the hidden peer (got ${document.activeElement?.id || document.activeElement?.tagName})`,
);
});
test('opening Data Layers in Cockpit hands the focus from the folded Contact card to its toggle', (t) => {
document.body.innerHTML = `
<div id="left-panel-stack">
<div id="data-panel" data-panel-id="data-panel" class="active collapsed"><button class="panel-collapse-btn" data-collapse-target="data-panel"></button></div>
</div>
<aside id="cockpit-context"><button id="cockpit-context-toggle"></button><button id="cockpit-weather-toggle"></button></aside>`;
const store = usePanelChromeStore(createPinia());
const cockpit = {
active: true,
contextCollapsed: false,
setContextCollapsed(collapsed) {
this.contextCollapsed = collapsed;
},
setSignalCollapsed() {},
scheduleContextLayout() {},
};
const chrome = new PanelChrome({
elements: { _leftPanelStack: document.getElementById('left-panel-stack') },
operations: { _showToast() {}, _syncCctvPanelViewport() {} },
readHud: () => ({ visible: false, getVariant: () => null }),
readCockpit: () => cockpit,
readShareLinks: () => null,
readInitialShare: () => null,
readScrollRestoreOwner: () => null,
readDisplayScrollTop: () => 0,
store,
});
t.after(() => chrome.destroy());
followPanelState(store, 'data-panel', document.getElementById('data-panel'));
chrome._disclosurePanelIds = new Set(['data-panel']);
document.getElementById('cockpit-weather-toggle').focus();
chrome._togglePanel('data-panel');
assert.equal(
store.panels['data-panel']?.collapsed,
false,
'Data Layers opens',
);
assert.equal(cockpit.contextCollapsed, true, 'Contact folds for it');
assert.equal(document.activeElement?.id, 'cockpit-context-toggle');
});
+2 -5
View File
@@ -1,5 +1,5 @@
import PanelRailView from './PanelRailView.vue';
import { PANEL_RAIL_HOST_CLASS, PANEL_RAIL_ITEMS } from './panelRailCatalog.js';
import { PANEL_RAIL_HOST_CLASS } from './panelRailCatalog.js';
import { usePanelStore } from './stores/panels.js';
/**
@@ -71,7 +71,6 @@ export class PanelNavigation {
? [...stack.children]
.filter((panel) => panel.matches('[data-panel-id]'))
.map((panel) => {
const shownBy = PANEL_RAIL_ITEMS[panel.id]?.shownBy;
return {
id: panel.id,
title:
@@ -79,9 +78,7 @@ export class PanelNavigation {
.querySelector('.panel-title, .pp-header-label')
?.textContent.trim() || panel.id,
open: !panel.classList.contains('collapsed'),
available:
!panel.hidden &&
(!shownBy || panel.classList.contains(shownBy)),
available: !panel.hidden,
};
})
: [];
+2 -4
View File
@@ -22,8 +22,6 @@ function panel(id, { collapsed = true, hidden = false, title = '' } = {}) {
element.className = collapsed
? 'panel-collapsible collapsed'
: 'panel-collapsible';
// Data Layers shows only while `active` (the `f` shortcut toggles it).
if (id === 'data-panel') element.classList.add('active');
element.hidden = hidden;
if (title) element.innerHTML = `<span class="panel-title">${title}</span>`;
return element;
@@ -132,8 +130,8 @@ test('the rails follow disclosure and availability changes', async () => {
['global-context-panel', 'false'],
['host-panel', 'false'],
]);
// `f` hides Data Layers outright, so the rail stops offering it.
document.getElementById('data-panel').classList.remove('active');
// A hidden panel leaves its rail.
document.getElementById('data-panel').hidden = true;
await new Promise((resolve) => setTimeout(resolve, 0));
await nextTick();
assert.deepEqual(railItems(left), [['scene-panel', 'true']]);
+3 -8
View File
@@ -7,16 +7,11 @@ export const PANEL_RAIL_HOST_CLASS = 'gev-panel-rail';
export const PANEL_RAIL_FALLBACK_ICON = 'more_horiz';
/**
* How each side panel appears on its rail. Labels are the panels' own titles.
* `shownBy` names a class the panel needs to be shown at all (`f` toggles
* Data Layers' `active`). `context` is the label's translation context.
* How each side panel appears on its rail. Labels are the panels' own titles;
* `context` is the label's translation context.
*/
export const PANEL_RAIL_ITEMS = Object.freeze({
'data-panel': {
icon: 'layers',
label: msg('DATA LAYERS'),
shownBy: 'active',
},
'data-panel': { icon: 'layers', label: msg('DATA LAYERS') },
'utilities-panel': { icon: 'handyman', label: msg('UTILITIES') },
'scene-panel': { icon: 'movie', label: msg('AUTHORING') },
// `context` keeps the panel's name apart from the satellite class of the