Skip to content

A one-of-a-kind resume builder that keeps your privacy in mind. Completely secure, customizable, portable, open-source and free forever. Try it out today!

fix: focus application search with keyboard shortcuts (#3843)

Amruth Pillai0a9f421bab3c
diff --git a/apps/mobile/scripts/layout.test.mjs b/apps/mobile/scripts/layout.test.mjs
index b717ef9b0..cded309cc 100644
--- a/apps/mobile/scripts/layout.test.mjs
+++ b/apps/mobile/scripts/layout.test.mjs
@@ -39,6 +39,7 @@ const routes = {
};
const mocks = {
react,
+ "@/shell/key-commands": { useKeyCommands() {} },
"react-native": native,
"react-native-safe-area-context": safe,
"@lingui/react/macro": { useLingui: () => ({ t: tag }) },
diff --git a/apps/mobile/scripts/search-shortcut.test.mjs b/apps/mobile/scripts/search-shortcut.test.mjs
new file mode 100644
index 000000000..1d78855a6
--- /dev/null
+++ b/apps/mobile/scripts/search-shortcut.test.mjs
@@ -0,0 +1,171 @@
+// Execute collection search and modal lifetimes through the shipped hardware-command owner. Host proof only.
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { createRequire } from "node:module";
+
+const serverRequire = createRequire(new URL("../../server/package.json", import.meta.url));
+const { transformSync } = createRequire(serverRequire.resolve("tsx"))("esbuild");
+const element = (type, props, ...children) => ({ type, props: { ...props, children } });
+let current;
+let cursor;
+let focused = true;
+let commands = [];
+let dispatch;
+const react = {
+ createElement: element,
+ useRef(initial) {
+ const index = cursor++;
+ return (current.hooks[index] ??= { current: initial });
+ },
+ useState(initial) {
+ const index = cursor++;
+ const hooks = current.hooks;
+ if (!(index in hooks)) hooks[index] = initial;
+ return [hooks[index], (value) => (hooks[index] = value)];
+ },
+ useCallback: (callback) => callback,
+ useEffect(effect, deps) {
+ const index = cursor++;
+ const previous = current.hooks[index];
+ if (deps && previous?.deps && deps.every((value, i) => Object.is(value, previous.deps[i]))) return;
+ const hooks = current.hooks;
+ current.effects.push(() => {
+ previous?.cleanup?.();
+ hooks[index] = { deps, cleanup: effect() };
+ });
+ },
+};
+const theme = {
+ colors: {},
+ radius: {},
+ size: { hit: 44, icon: { row: 20 } },
+ space: {},
+ type: {},
+ shadows: { e3: {} },
+};
+const mocks = {
+ react,
+ "expo-router": { useIsFocused: () => focused },
+ "../../modules/key-commands": {
+ keyCommands: {
+ setCommands: (next) => (commands = next),
+ addListener: (_event, listener) => (dispatch = listener),
+ },
+ },
+ "react-native": {
+ AccessibilityInfo: { isScreenReaderEnabled: async () => false, addEventListener() {} },
+ StyleSheet: { hairlineWidth: 1 },
+ TextInput: "TextInput",
+ View: "View",
+ I18nManager: { isRTL: false },
+ Keyboard: { dismiss() {} },
+ Platform: { OS: "ios" },
+ useWindowDimensions: () => ({ width: 390, height: 844, fontScale: 1 }),
+ },
+ "@lingui/react/macro": { useLingui: () => ({ t: (parts) => parts.join("") }) },
+ "@/ui": { useTheme: () => theme, Text: "Text", Icon: "Icon", IconButton: "IconButton" },
+ "@lodev09/react-native-true-sheet": { TrueSheet: "TrueSheet" },
+ "react-native-reanimated": {},
+ "react-native-worklets": {},
+ "./button": {},
+ "./motion": { useIsWide: () => false, useReducedMotion: () => false },
+ "./safe-area": { useWindowSafeAreaInsets: () => ({ top: 44 }) },
+ "./text": { Text: "Text" },
+ "./theme": { useTheme: () => theme },
+};
+function load(path) {
+ const module = { exports: {} };
+ const code = transformSync(readFileSync(new URL(`../src/${path}`, import.meta.url), "utf8"), {
+ loader: path.endsWith(".tsx") ? "tsx" : "ts",
+ format: "cjs",
+ jsx: "transform",
+ }).code;
+ new Function("React", "require", "module", "exports", code)(
+ react,
+ (name) => {
+ assert.ok(name in mocks, `Missing native boundary: ${name}`);
+ return mocks[name];
+ },
+ module,
+ module.exports,
+ );
+ return module.exports;
+}
+const keyCommands = load("shell/key-commands.ts");
+mocks["@/shell/key-commands"] = keyCommands;
+const { CollectionHeader } = load("components/collection-header.tsx");
+const { Sheet, ConfirmDialog } = load("ui/overlays.tsx");
+function mount(component, props) {
+ const instance = { hooks: [], effects: [] };
+ return {
+ render(next = props) {
+ current = instance;
+ cursor = 0;
+ instance.effects = [];
+ const tree = component(next);
+ for (const effect of instance.effects) effect();
+ return tree;
+ },
+ unmount() {
+ for (const hook of instance.hooks) hook?.cleanup?.();
+ },
+ };
+}
+const nodes = (tree) =>
+ !tree || typeof tree !== "object"
+ ? []
+ : Array.isArray(tree)
+ ? tree.flatMap(nodes)
+ : [tree, ...nodes(tree.props.children)];
+const props = {
+ title: "Applications",
+ searchLabel: "Search applications",
+ placeholder: "Role, company or contact",
+ value: "",
+ onChangeText() {},
+};
+const header = mount(CollectionHeader, props);
+assert.equal(
+ nodes(header.render()).some((node) => node.type === "TextInput"),
+ false,
+);
+const searchId = commands.find((command) => command.input === "f").id;
+header.render({ ...props, value: "Cedar" });
+dispatch({ id: searchId });
+let input = nodes(header.render({ ...props, value: "Cedar" })).find((node) => node.type === "TextInput");
+assert.equal(input.props.autoFocus, true, "Hardware search must open and focus the collapsed search");
+let focuses = 0;
+input.props.ref.current = { focus: () => focuses++ };
+header.render({ ...props, value: "Cedar" });
+dispatch({ id: searchId });
+assert.equal(focuses, 1, "Existing filtered search must regain focus");
+input = nodes(header.render({ ...props, value: "Cedar" })).find((node) => node.type === "TextInput");
+assert.equal(input.props.value, "Cedar", "Refocusing must preserve the filter");
+
+const sheetProps = { open: true, onClose() {}, children: null };
+const sheet = mount(Sheet, sheetProps);
+sheet.render();
+assert.deepEqual(commands, [], "An open sheet must release background shortcuts");
+dispatch({ id: searchId });
+assert.equal(focuses, 1, "A late native event must not focus a field behind a sheet");
+const alertProps = { open: true, confirmLabel: "Delete", onConfirm() {}, onCancel() {} };
+const alert = mount(ConfirmDialog, alertProps);
+alert.render();
+sheet.render({ ...sheetProps, open: false });
+assert.deepEqual(commands, [], "Closing one overlay must preserve the other overlay's suspension");
+alert.unmount();
+assert.ok(commands.some((command) => command.input === "f"));
+dispatch({ id: searchId });
+assert.equal(focuses, 2, "Search must resume after the final overlay closes");
+sheet.unmount();
+
+header.render({ ...props, disabled: true });
+assert.deepEqual(commands, []);
+dispatch({ id: searchId });
+assert.equal(focuses, 2, "Disabled search must ignore late native events");
+header.render();
+focused = false;
+header.render();
+assert.deepEqual(commands, [], "An unfocused screen must unregister its search shortcut");
+header.unmount();
+console.log("PASS native collection search focus, retained filter, nested modal suspension and screen lifetime");
diff --git a/apps/mobile/scripts/sheets.test.mjs b/apps/mobile/scripts/sheets.test.mjs
index bdb81bbf2..816cf75dc 100644
--- a/apps/mobile/scripts/sheets.test.mjs
+++ b/apps/mobile/scripts/sheets.test.mjs
@@ -31,6 +31,7 @@ const theme = {
const tag = (parts, ...values) => parts.reduce((text, part, index) => text + part + (values[index] ?? ""), "");
const mocks = {
react,
+ "@/shell/key-commands": { useKeyCommandBlocker() {} },
"react-native": {
AccessibilityInfo: { isScreenReaderEnabled: async () => false, addEventListener() {} },
Platform: { OS: "ios" },
diff --git a/apps/mobile/scripts/toast.test.mjs b/apps/mobile/scripts/toast.test.mjs
index 9c21fa304..8bd7078d1 100644
--- a/apps/mobile/scripts/toast.test.mjs
+++ b/apps/mobile/scripts/toast.test.mjs
@@ -25,6 +25,7 @@ const theme = {
};
const mocks = {
react,
+ "@/shell/key-commands": { useKeyCommandBlocker() {} },
"react-native": {
AccessibilityInfo: {
isScreenReaderEnabled: async () => false,
diff --git a/apps/mobile/src/components/collection-header.tsx b/apps/mobile/src/components/collection-header.tsx
index 2ae63cb22..2c4ef70d6 100644
--- a/apps/mobile/src/components/collection-header.tsx
+++ b/apps/mobile/src/components/collection-header.tsx
@@ -1,7 +1,8 @@
-import type { ReactNode } from "react";
+import type { ComponentRef, ReactNode } from "react";
import { useLingui } from "@lingui/react/macro";
-import { useState } from "react";
+import { useRef, useState } from "react";
import { I18nManager, Keyboard, TextInput, View, useWindowDimensions } from "react-native";
+import { useKeyCommands } from "@/shell/key-commands";
import { Icon, IconButton, Text, useTheme } from "@/ui";
type CollectionHeaderProps = {
@@ -40,6 +41,16 @@ export function CollectionHeader({
const { t } = useLingui();
const { colors, radius, size, space, type } = useTheme();
const [searching, setSearching] = useState(Boolean(value));
+ const [focusOnOpen, setFocusOnOpen] = useState(false);
+ const searchRef = useRef<ComponentRef<typeof TextInput>>(null);
+ const openSearch = () => {
+ setFocusOnOpen(true);
+ setSearching(true);
+ searchRef.current?.focus();
+ };
+ useKeyCommands(
+ searchLabel && !disabled ? [{ id: "collection.search", input: "f", title: searchLabel, run: openSearch }] : [],
+ );
const { fontScale } = useWindowDimensions();
const stacked = fontScale > 1.3;
return (
@@ -67,6 +78,7 @@ export function CollectionHeader({
>
<Icon name="magnifying-glass" size={size.icon.row} color={colors.ink3} />
<TextInput
+ ref={searchRef}
accessibilityLabel={searchLabel}
placeholder={placeholder}
placeholderTextColor={colors.ink3}
@@ -75,7 +87,7 @@ export function CollectionHeader({
maxLength={maxLength}
onChangeText={onChangeText}
editable={!disabled}
- autoFocus={!value}
+ autoFocus={focusOnOpen}
autoCorrect={false}
autoCapitalize="none"
returnKeyType="search"
@@ -115,12 +127,7 @@ export function CollectionHeader({
}}
>
{searchLabel ? (
- <IconButton
- icon="magnifying-glass"
- label={searchLabel}
- disabled={disabled}
- onPress={() => setSearching(true)}
- />
+ <IconButton icon="magnifying-glass" label={searchLabel} disabled={disabled} onPress={openSearch} />
) : null}
{actions}
</View>
diff --git a/apps/mobile/src/shell/key-commands.ts b/apps/mobile/src/shell/key-commands.ts
index d8e02b4be..598800556 100644
--- a/apps/mobile/src/shell/key-commands.ts
+++ b/apps/mobile/src/shell/key-commands.ts
@@ -10,8 +10,10 @@ type Owner = { readonly current: readonly KeyBinding[] };
// Every mounted `useKeyCommands`, in mount order. For the same keys the latest mounted one wins.
const owners = new Set<Owner>();
+let blockers = 0;
const active = () => {
+ if (blockers) return [];
const byKey = new Map<string, KeyBinding>();
for (const owner of owners)
for (const binding of owner.current) byKey.set(`${binding.input}:${!!binding.shift}`, binding);
@@ -21,6 +23,19 @@ const active = () => {
const sync = () =>
keyCommands?.setCommands(active().map(({ id, input, shift, title }) => ({ id, input, shift: !!shift, title })));
+/** Sheets and alerts suspend background commands, including late native events. */
+export function useKeyCommandBlocker(open: boolean) {
+ useEffect(() => {
+ if (!open) return;
+ blockers++;
+ sync();
+ return () => {
+ blockers--;
+ sync();
+ };
+ }, [open]);
+}
+
keyCommands?.addListener("onKeyCommand", ({ id }) =>
active()
.find((binding) => binding.id === id)
diff --git a/apps/mobile/src/ui/overlays.tsx b/apps/mobile/src/ui/overlays.tsx
index deec25688..22f4eb9a1 100644
--- a/apps/mobile/src/ui/overlays.tsx
+++ b/apps/mobile/src/ui/overlays.tsx
@@ -31,6 +31,7 @@ import { haptics, useIsWide, useReducedMotion } from "./motion";
import { useWindowSafeAreaInsets } from "./safe-area";
import { Text } from "./text";
import { useTheme } from "./theme";
+import { useKeyCommandBlocker } from "@/shell/key-commands";
const android = Platform.OS === "android";
@@ -102,6 +103,7 @@ export function Sheet({
scroll = true,
dismissible = true,
}: SheetProps) {
+ useKeyCommandBlocker(open);
const { t } = useLingui();
const { colors, radius, size, space } = useTheme();
const wide = useIsWide();
@@ -417,6 +419,7 @@ export function ConfirmDialog({
onConfirm,
onCancel,
}: ConfirmDialogProps) {
+ useKeyCommandBlocker(open);
const { t } = useLingui();
const { colors, radius, shadows, space } = useTheme();
const { width, height, fontScale } = useWindowDimensions();
diff --git a/apps/web/src/routes/dashboard/applications/index.tsx b/apps/web/src/routes/dashboard/applications/index.tsx
index 5a177cd73..5b0369e60 100644
--- a/apps/web/src/routes/dashboard/applications/index.tsx
+++ b/apps/web/src/routes/dashboard/applications/index.tsx
@@ -1,6 +1,7 @@
import type { Application, ApplicationSummary } from "@/features/applications/types";
import { t } from "@lingui/core/macro";
import { Plural, Trans } from "@lingui/react/macro";
+import { useHotkey } from "@tanstack/react-hotkeys";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { createFileRoute, stripSearchParams, useNavigate } from "@tanstack/react-router";
import { useCallback, useDeferredValue, useEffect, useRef, useState } from "react";
@@ -105,6 +106,8 @@ function RouteComponent() {
const phone = useBreakpoint() === "mobile";
// Typing filters at once; the URL only seeds the search.
const [query, setQuery] = useState(q);
+ const pageRef = useRef<HTMLDivElement>(null);
+ const searchRef = useRef<HTMLInputElement>(null);
const [capture, setCapture] = useState(takePostingCapture);
const [adding, setAdding] = useState(!!capture);
const [importing, setImporting] = useState(false);
@@ -118,6 +121,14 @@ function RouteComponent() {
const [viewSwitched, setViewSwitched] = useState(false);
const { data: applications, isPending, isError, isFetching, refetch } = useQuery(applicationsListQueryOptions());
+ useHotkey(
+ "/",
+ (event) => {
+ if (event.keyCode === 229) return;
+ searchRef.current?.focus();
+ },
+ { enabled: Boolean(applications?.length), target: pageRef },
+ );
const queryClient = useQueryClient();
const { data: fullApplications } = useQuery({ ...applicationsFullListQueryOptions(), enabled: exporting });
@@ -243,7 +254,11 @@ function RouteComponent() {
};
return (
- <div className="mx-auto grid w-full max-w-[1180px] content-start gap-5 px-8 py-8 max-sm:px-4 max-sm:py-5">
+ <div
+ ref={pageRef}
+ tabIndex={-1}
+ className="mx-auto grid w-full max-w-[1180px] content-start gap-5 px-8 py-8 max-sm:px-4 max-sm:py-5"
+ >
<PageHeader
title={<Trans>Applications</Trans>}
actions={
@@ -312,7 +327,9 @@ function RouteComponent() {
className="pointer-events-none absolute start-2.5 top-1/2 -translate-y-1/2 text-ink-3"
/>
<Input
+ ref={searchRef}
type="search"
+ aria-keyshortcuts="/"
aria-label={t`Search applications`}
placeholder={t`Search role, company or contact`}
value={query}
diff --git a/docs/guides/keyboard-shortcuts.mdx b/docs/guides/keyboard-shortcuts.mdx
index 7d4973173..f37cbe1e3 100644
--- a/docs/guides/keyboard-shortcuts.mdx
+++ b/docs/guides/keyboard-shortcuts.mdx
@@ -1,6 +1,6 @@
---
title: "Keyboard shortcuts"
-description: "The keyboard shortcuts in Reactive Resume: the command bar, Documents, the resume and letter editors, text formatting, the assistant and proposed edits."
+description: "The keyboard shortcuts in Reactive Resume: the command bar, Documents, Applications, the resume and letter editors, text formatting, the assistant and proposed edits."
---
This page lists the keyboard shortcuts in Reactive Resume, grouped by where they work.
@@ -10,7 +10,8 @@ The app's tooltips and buttons show the Mac symbols on every system.
<Note>
Shortcuts made of a single key, such as <kbd>N</kbd> or <kbd>1</kbd>, don't work while you're typing in a text field,
- so they never get in the way of your writing. Shortcuts with <kbd>⌘</kbd> work everywhere.
+ so they never get in the way of your writing. Shortcuts with <kbd>⌘</kbd> can work while typing. In the native app,
+ sheets and alerts pause background app shortcuts.
</Note>
## Everywhere
@@ -27,7 +28,7 @@ The app's tooltips and buttons show the Mac symbols on every system.
| Shortcut | What it does |
| ---------------- | -------------------------------------------------------------------------------- |
| <kbd>N</kbd> | Open **New** for the section you're in. |
-| <kbd>/</kbd> | Jump to the search box on **Documents**. |
+| <kbd>/</kbd> | Jump to the search box on **Documents** or **Applications** in the web app. |
| <kbd>Enter</kbd> | In the **Documents** search box, open the first result. |
| <kbd>↓</kbd> | In the **Documents** search box, move to the first result. |
| <kbd>Esc</kbd> | In the **Documents** search box, clear the search; press again to leave the box. |
@@ -35,6 +36,10 @@ The app's tooltips and buttons show the Mac symbols on every system.
| <kbd>Esc</kbd> | Cancel renaming a document on its card. |
| <kbd>Esc</kbd> | Clear the Documents selection when focus is outside a text field. |
+In the native mobile app, use <kbd>⌘</kbd> <kbd>F</kbd> on an iPad hardware keyboard or <kbd>Ctrl</kbd> <kbd>F</kbd>
+on Android to open or refocus the current collection's search. Your filter stays in place. These native search
+shortcuts pause while a sheet or alert is open.
+
## Resume editor
| Shortcut | What it does |
diff --git a/docs/guides/tracking-job-applications.mdx b/docs/guides/tracking-job-applications.mdx
index e51a57746..cd54a406d 100644
--- a/docs/guides/tracking-job-applications.mdx
+++ b/docs/guides/tracking-job-applications.mdx
@@ -81,6 +81,15 @@ In a narrow phone browser, the web page shows **List**, **Insights** and **Calen
Type in **Search applications** to filter the list as you type. Search looks at the role, company, location, contact names and tags. If nothing matches, select **Clear search**.
+In the web app, press <kbd>/</kbd> with an Applications view focused, outside a text field, to focus search. In the native mobile app, use <kbd>⌘</kbd> <kbd>F</kbd> on an iPad hardware keyboard or <kbd>Ctrl</kbd> <kbd>F</kbd> on Android. Open sheets and alerts keep keyboard focus.
+
+<Frame caption="Search focused on Applications, filtering the list to a fictional company">
+ <img
+ src="/images/guides/career/applications-search-shortcut.png"
+ alt="Applications search focused with Cedar entered and one Product designer role at Fictional Cedar in the list"
+ />
+</Frame>
+
In the web app, **Show closed applications** adds closed applications to the List, Board and Calendar views. The native mobile calendar shows only open applications. Insights always counts every application.
## Acting on several applications at once
diff --git a/docs/images/guides/career/applications-search-shortcut.png b/docs/images/guides/career/applications-search-shortcut.png
new file mode 100644
index 000000000..5d065beb9
Binary files /dev/null and b/docs/images/guides/career/applications-search-shortcut.png differ
diff --git a/tests/e2e/specs/applications-search-shortcut.spec.ts b/tests/e2e/specs/applications-search-shortcut.spec.ts
new file mode 100644
index 000000000..3fa97bbcf
--- /dev/null
+++ b/tests/e2e/specs/applications-search-shortcut.spec.ts
@@ -0,0 +1,69 @@
+import { expect, test } from "../fixtures/test";
+
+test("Applications search shortcut focuses every view without stealing typing or dialog focus", async ({
+ authPage: page,
+}, testInfo) => {
+ for (const [company, role] of [
+ ["Fictional Cedar", "Product designer"],
+ ["Fictional Orbit", "Engineer"],
+ ]) {
+ await expect(await page.request.post("/api/openapi/applications", { data: { company, role } })).toBeOK();
+ }
+ await page.goto("/dashboard/applications");
+ const search = page.getByRole("searchbox", { name: "Search applications", exact: true });
+ const save = page.getByRole("button", { name: "Save job", exact: true });
+ await expect(search).toBeVisible();
+ await save.focus();
+ await page.keyboard.press("/");
+ await expect(search).toBeFocused();
+ await expect(search).toHaveValue("");
+ await search.fill("Cedar");
+ await expect(page.getByText("Product designer", { exact: true })).toBeVisible();
+ await expect(page.getByText("Engineer", { exact: true })).toHaveCount(0);
+ await page.keyboard.press("/");
+ await expect(search).toHaveValue("Cedar/");
+ await search.fill("");
+
+ for (const view of ["Board", "Calendar", "Insights", "List"]) {
+ const tab = page.getByRole("tab", { name: view, exact: true });
+ await tab.click();
+ await tab.focus();
+ await page.keyboard.press("/");
+ await expect(search).toBeFocused();
+ }
+ await search.fill("Cedar");
+ await expect(page.getByText("Product designer", { exact: true })).toBeVisible();
+ await expect(page.getByText("Engineer", { exact: true })).toHaveCount(0);
+ await page.screenshot({ path: testInfo.outputPath("applications-search-shortcut.png"), animations: "disabled" });
+ await search.fill("");
+
+ const documents = page.getByRole("complementary").getByRole("link", { name: "Documents", exact: true });
+ await documents.focus();
+ await page.keyboard.press("/");
+ await expect(documents).toBeFocused();
+
+ await save.focus();
+ await page.keyboard.press("Control+/");
+ await expect(save).toBeFocused();
+ await save.dispatchEvent("keydown", { key: "/", code: "Slash", isComposing: true });
+ await expect(save).toBeFocused();
+ await save.dispatchEvent("keydown", { key: "/", code: "Slash", keyCode: 229 });
+ await expect(save).toBeFocused();
+
+ await page.getByRole("button", { name: "More", exact: true }).click();
+ await page.getByRole("menuitem", { name: "Import CSV…", exact: true }).click();
+ const importing = page.getByRole("dialog", { name: "Import from CSV", exact: true, includeHidden: true });
+ const csv = importing.getByLabel("CSV data", { exact: true });
+ await csv.fill("Company,Role\nCedar,Designer");
+ await csv.press("/");
+ await expect(csv).toHaveValue("Company,Role\nCedar,Designer/");
+ const close = importing.getByRole("button", { name: "Close", exact: true });
+ await close.focus();
+ await page.keyboard.press("/");
+ await expect(close).toBeFocused();
+ await close.click();
+ await expect(importing).toHaveCount(0);
+ await save.focus();
+ await page.keyboard.press("/");
+ await expect(search).toBeFocused();
+});