Summary card links to the detailed analysis tab
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -9,13 +9,29 @@ export type Tab = { id: string; label: string; content: ReactNode };
|
||||
* shared link opens the same tab. Hidden panels stay mounted: a running
|
||||
* analysis keeps polling while another tab is open.
|
||||
*/
|
||||
/** Opens a tab from anywhere on the page (also when the hash is already that tab). */
|
||||
export function openTab(id: string) {
|
||||
history.replaceState(null, "", `#${id}`);
|
||||
window.dispatchEvent(new HashChangeEvent("hashchange"));
|
||||
}
|
||||
|
||||
export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {
|
||||
const [active, setActive] = useState(tabs[0]?.id);
|
||||
const buttons = useRef<(HTMLButtonElement | null)[]>([]);
|
||||
|
||||
const root = useRef<HTMLDivElement>(null);
|
||||
|
||||
// A link to #<tab> (on load, or from elsewhere on the page) opens that tab and scrolls to it.
|
||||
useEffect(() => {
|
||||
const fromHash = window.location.hash.slice(1);
|
||||
if (tabs.some((t) => t.id === fromHash)) setActive(fromHash);
|
||||
const open = () => {
|
||||
const id = window.location.hash.slice(1);
|
||||
if (!tabs.some((t) => t.id === id)) return;
|
||||
setActive(id);
|
||||
root.current?.scrollIntoView({ behavior: "smooth", block: "start" });
|
||||
};
|
||||
open();
|
||||
window.addEventListener("hashchange", open);
|
||||
return () => window.removeEventListener("hashchange", open);
|
||||
}, [tabs]);
|
||||
|
||||
function choose(id: string) {
|
||||
@@ -33,7 +49,7 @@ export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="tabs">
|
||||
<div className="tabs" ref={root}>
|
||||
<div className="tab-list" role="tablist" aria-label={label}>
|
||||
{tabs.map((t, i) => (
|
||||
<button
|
||||
|
||||
Reference in New Issue
Block a user