Files
outline/app/hooks/useKeyboardShortcutsQuery.tsx
T
Tom Moor 8fb8f4d3d4 feat: Alt+Up/Down moves to the previous/next document in the sidebar (#14034)
* feat: Alt+Up/Down moves to the previous/next document in the sidebar

* feat: Sidebar keyboard navigation works across collections and root rows
2026-10-11 15:33:19 -04:00

32 lines
1.1 KiB
TypeScript

import { useEffect } from "react";
import { useTranslation } from "react-i18next";
import KeyboardShortcuts from "~/components/KeyboardShortcuts";
import useQuery from "./useQuery";
import useStores from "./useStores";
/**
* Open the keyboard shortcuts guide when a "shortcuts" param is present in the
* query string, optionally filtered by the value of the param. This is used to
* deep link to the guide from external sources, such as emails.
*/
export default function useKeyboardShortcutsQuery() {
const { t } = useTranslation();
const { dialogs } = useStores();
const query = useQuery();
const shortcutsQuery = query.get("shortcuts");
useEffect(() => {
if (shortcutsQuery === null) {
return;
}
dialogs.openGuide({
title: t("Keyboard shortcuts"),
content: <KeyboardShortcuts defaultQuery={shortcutsQuery} />,
});
// Only the query param should open the guide, re-running when the other
// dependencies change would reopen an already dismissed dialog.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [shortcutsQuery]);
}