diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsx index 7d0bc777b..e439529f3 100644 --- a/apps/client/src/widgets/ribbon/Ribbon.tsx +++ b/apps/client/src/widgets/ribbon/Ribbon.tsx @@ -1,4 +1,4 @@ -import { useMemo, useState } from "preact/hooks"; +import { useEffect, useMemo, useState } from "preact/hooks"; import { t } from "../../services/i18n"; import { useNoteContext } from "../react/hooks"; import "./style.css"; @@ -162,6 +162,14 @@ export default function Ribbon() { const [ activeTabIndex, setActiveTabIndex ] = useState(); const filteredTabs = useMemo(() => TAB_CONFIGURATION.filter(tab => typeof tab.show === "boolean" ? tab.show : tab.show?.(titleContext)), [ titleContext, note ]); + // Automatically activate the first ribbon tab that needs to be activated whenever a note changes. + useEffect(() => { + const tabToActivate = filteredTabs.find(tab => typeof tab.activate === "boolean" ? tab.activate : tab.activate?.(titleContext)); + if (tabToActivate) { + setActiveTabIndex(tabToActivate.index); + } + }, [ note?.noteId ]); + return (