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: finish the CollapsibleText children-mode review fixes (#4170)
Adam Eivy4ff7306dfd70
diff --git a/.changelog/next/changed-issue-4170.md b/.changelog/next/changed-issue-4170.mdindex 110a96a860..d3c9f08ac4 100644--- a/.changelog/next/changed-issue-4170.md+++ b/.changelog/next/changed-issue-4170.md@@ -1 +1 @@-- CollapsibleText gained a children-based max-height variant for content CSS line-clamp cannot clamp; the CoS agent card's task description now uses it (measured overflow + aria-expanded/aria-controls) instead of its own character-count heuristic+- CollapsibleText gained a children-based max-height variant for content CSS line-clamp cannot clamp; the CoS agent card's task description now uses it (measured overflow + aria-expanded/aria-controls) instead of its own character-count heuristic, and keyboard focus landing on a link inside a clipped preview now expands it rather than scrolling it out of reachdiff --git a/client/src/components/ui/CollapsibleText.jsx b/client/src/components/ui/CollapsibleText.jsxindex dff8e4079d..dcf076738c 100644--- a/client/src/components/ui/CollapsibleText.jsx+++ b/client/src/components/ui/CollapsibleText.jsx@@ -55,7 +55,11 @@ const CLAMP_CLASS = {* never change its box and a resize callback bound to it alone would never fire;* the inner wrapper is uncapped, so its height tracks the real content and a* changed child re-measures without needing `children` (a fresh element object- * every render) in the effect deps.+ * every render, which would churn the observer on every parent re-render) in the+ * effect deps. Switching *modes* still has to re-run it, though — the rendered+ * element swaps between `<p>` and the capped `<div>`, so the effect's captured+ * element would otherwise stay bound to the detached one and never measure.+ * That's what `hasChildren` (a stable boolean) is doing in the deps.** Two separate guards keep the toggle from vanishing mid-expand (which would* strand the user in the expanded wall of text with no way back): the effect@@ -84,7 +88,13 @@ export default function CollapsibleText({const [isOverflowing, setIsOverflowing] = useState(false);const ref = useRef(null);const innerRef = useRef(null);- const hasChildren = children != null && children !== false;+ // An empty list or an empty string is *no* children, not "children that+ // happen to be blank" — a caller doing `<CollapsibleText text={fallback}>+ // {items.map(…)}</CollapsibleText>` over an empty list must get the text+ // fallback, not an empty capped box with its `text` silently dropped.+ const hasChildren = Array.isArray(children)+ ? children.length > 0+ : children != null && children !== false && children !== '';useEffect(() => {if (expanded) return;@@ -100,6 +110,7 @@ export default function CollapsibleText({}, [text, hasChildren, expanded]);const clamp = CLAMP_CLASS[lines] || CLAMP_CLASS[2];+const renderContent = () => {if (hasChildren) {return (@@ -108,6 +119,15 @@ export default function CollapsibleText({id={id}className={`break-words ${className} ${expanded ? '' : 'overflow-hidden'}`}style={expanded ? undefined : { maxHeight }}+ // `overflow-hidden` is a scroll container with no visible scrollbar,+ // and children may hold links, buttons or a horizontally-scrollable+ // <pre>. Tabbing to one below the cap would scroll the preview to+ // reveal it with no way to scroll back — and `aria-expanded="false"`+ // would be a lie, since the content is fully in the tab order.+ // Expanding on focus keeps the claim honest and the target on screen.+ // Gated on real overflow: content that fits is never clipped, so+ // expanding it would only mint a no-op "Show less" into the tab order.+ onFocus={() => { if (isOverflowing) setExpanded(true); }}><div ref={innerRef}>{children}</div></div>diff --git a/client/src/components/ui/CollapsibleText.test.jsx b/client/src/components/ui/CollapsibleText.test.jsxindex 242287b5ab..237c8453c7 100644--- a/client/src/components/ui/CollapsibleText.test.jsx+++ b/client/src/components/ui/CollapsibleText.test.jsx@@ -237,6 +237,62 @@ describe('CollapsibleText children (max-height) variant', () => {expect(observed).toContain(box.firstElementChild);});+ it('measures children that arrive after mount', () => {+ // Switching modes swaps the rendered element from <p> to the capped <div>,+ // so an effect that doesn't re-run stays bound to the now-detached <p> —+ // which has no layout and never gets a resize callback. The content would+ // clip at maxHeight with no Show more affordance at all.+ const spy = forceOverflow();+ spy.mockReturnValue(0);+ const { rerender } = render(<CollapsibleText id="c8">{null}</CollapsibleText>);+ expect(screen.queryByRole('button')).not.toBeInTheDocument();++ spy.mockReturnValue(500);+ rerender(<CollapsibleText id="c8"><p>tall rendered markdown</p></CollapsibleText>);+ expect(screen.getByRole('button', { name: /Show more/ })).toBeInTheDocument();+ });++ it('treats an empty child list as no children so the text fallback still renders', () => {+ // `<CollapsibleText text={fallback}>{items.map(…)}</CollapsibleText>` over an+ // empty list must not yield an empty capped box with `text` silently dropped.+ render(<CollapsibleText id="c9" text="plain fallback">{[]}</CollapsibleText>);+ expect(screen.getByText('plain fallback')).toBeInTheDocument();+ expect(document.getElementById('c9')).toHaveClass('line-clamp-2');+ });++ it('expands when focus lands inside the capped region', () => {+ // The cap is a scroll container with no visible scrollbar. Tabbing to a link+ // below it would scroll the preview to reveal the target with no way back,+ // while `aria-expanded="false"` claimed content that is fully in the tab+ // order was hidden.+ forceOverflow();+ render(+ <CollapsibleText id="c10">+ <a href="/r">buried link</a>+ </CollapsibleText>+ );++ expect(screen.getByRole('button')).toHaveAttribute('aria-expanded', 'false');+ fireEvent.focus(screen.getByRole('link', { name: 'buried link' }));++ expect(screen.getByRole('button', { name: /Show less/ })).toHaveAttribute('aria-expanded', 'true');+ expect(document.getElementById('c10')).not.toHaveClass('overflow-hidden');+ });++ it('leaves fitting children alone when focus lands inside them', () => {+ // Nothing is clipped, so there is nothing to reveal — expanding here would+ // only mint a no-op "Show less" button into the tab order.+ render(+ <CollapsibleText id="c11">+ <a href="/r">visible link</a>+ </CollapsibleText>+ );++ fireEvent.focus(screen.getByRole('link', { name: 'visible link' }));+ expect(screen.queryByRole('button')).not.toBeInTheDocument();+ expect(document.getElementById('c11')).toHaveClass('overflow-hidden');+ });+it('keeps the toggle when a resize fires against the uncapped container', () => {// Same in-flight-callback race as the line-clamp path: expanding removes the// cap, and a resize notification already in flight would otherwise measure