Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: manage chord diagram popover focus (#9844)
Adam Eivy9101c71e32ed
diff --git a/client/src/components/songbook/TabSheetView.jsx b/client/src/components/songbook/TabSheetView.jsxindex 1528c78554..bd9c0cf492 100644--- a/client/src/components/songbook/TabSheetView.jsx+++ b/client/src/components/songbook/TabSheetView.jsx@@ -2,6 +2,8 @@ import { createPortal } from 'react-dom';import { memo, useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';import { parseTabSheet, TAB_ARTICULATIONS, chordLineSegments, pairedLineChunks, chordLyricRows } from '../../lib/tabNotation.js';import usePopoverPosition from '../../hooks/usePopoverPosition.js';+import useFocusTrap from '../../hooks/useFocusTrap.js';+import useEscapeKey from '../../hooks/useEscapeKey.js';import ChordDiagram from './ChordDiagram.jsx';import { activeCtrlClass, ctrlBtnClass } from './constants.js';@@ -155,6 +157,11 @@ function TabSheetView({// re-measure so the dialog moves to the newly-tapped token.contentDeps: [popover?.key, popover?.name, instrumentView],});+ useFocusTrap(Boolean(popover && popoverStyle), popoverRef);+ useEscapeKey(Boolean(popover), () => {+ setPopover(null);+ anchorElRef.current?.focus();+ });// Tabstaff blocks explicitly expanded while in a non-guitar view.const [expandedStaffs, setExpandedStaffs] = useState(() => new Set());@@ -172,12 +179,9 @@ function TabSheetView({});}, []);- // Escape / tap-outside close while the popover is open.+ // Tap-outside close while the popover is open.useEffect(() => {if (!popover) return undefined;- const onKeyDown = (e) => {- if (e.key === 'Escape') setPopover(null);- };const onPointerDown = (e) => {if (popoverRef.current?.contains(e.target)) return;// Chord tokens manage their own open/toggle in onClick — closing here on@@ -185,10 +189,8 @@ function TabSheetView({if (e.target.closest?.('[aria-haspopup="dialog"]')) return;setPopover(null);};- document.addEventListener('keydown', onKeyDown);document.addEventListener('pointerdown', onPointerDown);return () => {- document.removeEventListener('keydown', onKeyDown);document.removeEventListener('pointerdown', onPointerDown);};}, [popover]);diff --git a/client/src/components/songbook/TabSheetView.test.jsx b/client/src/components/songbook/TabSheetView.test.jsxindex 810de7cd06..cdf7b21218 100644--- a/client/src/components/songbook/TabSheetView.test.jsx+++ b/client/src/components/songbook/TabSheetView.test.jsx@@ -79,6 +79,26 @@ describe('TabSheetView', () => {.toEqual([['C ', 'Hello '], ['G', 'world']]);});+ it('moves focus into the chord diagram, traps Tab, and restores focus on Escape', () => {+ render(<TabSheetView text="C G" />);+ const trigger = screen.getByRole('button', { name: 'C' });+ trigger.focus();+ fireEvent.click(trigger);++ const dialog = screen.getByRole('dialog', { name: 'C chord voicing' });+ const close = screen.getByRole('button', { name: 'Close chord diagram' });+ expect(document.activeElement).toBe(close);++ const tab = new KeyboardEvent('keydown', { key: 'Tab', bubbles: true, cancelable: true });+ dialog.dispatchEvent(tab);+ expect(tab.defaultPrevented).toBe(true);+ expect(document.activeElement).toBe(close);++ fireEvent.keyDown(dialog, { key: 'Escape' });+ expect(screen.queryByRole('dialog')).toBeNull();+ expect(document.activeElement).toBe(trigger);+ });+it('keeps mid-word chords, rhythm marks and trailing changes intact in pasted pairs', () => {const { container } = render(<TabSheetView text={' Am | G/B F\nPaper lanterns glow'} />);const chunks = [...container.querySelectorAll('[data-chord-lyric-chunk]')];