diff --git a/changelog.d/1598-f-collapses-data-layers.md b/changelog.d/1598-f-collapses-data-layers.md index e0f4df4973..42bdc9d833 100644 --- a/changelog.d/1598-f-collapses-data-layers.md +++ b/changelog.d/1598-f-collapses-data-layers.md @@ -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). diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 879c2135fb..f3b2976028 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -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. diff --git a/src/mapSourceFocus.test.mjs b/src/mapSourceFocus.test.mjs index 22d00f2cf8..a3b24ba23d 100644 --- a/src/mapSourceFocus.test.mjs +++ b/src/mapSourceFocus.test.mjs @@ -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 = []; diff --git a/src/panelEscape.test.mjs b/src/panelEscape.test.mjs index 1177804d01..b3937beb94 100644 --- a/src/panelEscape.test.mjs +++ b/src/panelEscape.test.mjs @@ -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); diff --git a/src/ui/panelChrome.js b/src/ui/panelChrome.js index c5da55c43b..bf6e08c3fe 100644 --- a/src/ui/panelChrome.js +++ b/src/ui/panelChrome.js @@ -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( diff --git a/src/ui/panelChromeButtons.test.mjs b/src/ui/panelChromeButtons.test.mjs index 75d9e72493..3b0c833fcf 100644 --- a/src/ui/panelChromeButtons.test.mjs +++ b/src/ui/panelChromeButtons.test.mjs @@ -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 = ` +
`; 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 = ` + +