Mantle Query Input Focus Shortcut Migration Guide
Query.Input no longer takes the keyboardShortcut prop. The new FocusShortcut component from @ngrok/mantle/focus-shortcut does the same job for any focusable field: FocusShortcut.Field makes the slash key (/) focus its child, and FocusShortcut.Hint shows the / key where you place it. The behavior does not change: the same keys are skipped, the field carries aria-keyshortcuts="/", and the hint shows only while the field is empty, enabled, and not focused, on a device that can hover.
TL;DR: Replace <Query.Input keyboardShortcut … /> with <FocusShortcut.Root><FocusShortcut.Field><Query.Input …><FocusShortcut.Hint /></Query.Input></FocusShortcut.Field></FocusShortcut.Root>, and import FocusShortcut from @ngrok/mantle/focus-shortcut. Remove keyboardShortcut={false}. Where a component forwards a boolean to keyboardShortcut, render the wrapped field when the boolean is true and the plain field when it is false.
Codemod
From a mantle checkout:
In a project that installs @ngrok/mantle:
The rules apply steps 1, 2, and 3. They wrap each Query.Input that sets keyboardShortcut or keyboardShortcut={true}, put FocusShortcut.Hint first among its children, add the FocusShortcut import, and remove keyboardShortcut={false}. They remove the attribute through the syntax tree, so a string or a comment that names it stays. They find Query through its import from @ngrok/mantle/query, so a renamed import matches, and a part from another library or a local name that shadows the import stays. These stay manual:
- Step 4, because a forwarded value such as
keyboardShortcut={enabled}is known only at runtime. The type checker names each one. - A
Query.Inputwith akey, such as one in a.map(), because the key must move to the new outer element. Move it toFocusShortcut.Rootby hand. - A
Query.Inputwith a spread, because the spread can setchildrenor turn the shortcut on or off. This includeskeyboardShortcut={false}before a spread. A flag inside a spread object is also manual. - A
Query.Inputwith achildrenprop, or with text or an expression as a child. Put the hint first, and wrap text in an element: bare text beside the hint breaks a page that a browser translated. - A
Query.InputinsideField.Control,Slotunder any name, or anasChildpart (also through a spread or a ternary), because the part passes its ref and props to its one child. PutFocusShortcut.Rootoutside the part andFocusShortcut.Fieldinside it, around theQuery.Input. - A
Query.Inputwith JSX in a prop that also setskeyboardShortcut, or with a multi-line string, because the rewrite would change that JSX or the indent of the string. - A file that already has its own
FocusShortcutname, such as a local, a type-only import, or a namespace import, because the wrapper would read that binding. - Step 5, because a test query is a string.
The codemod leaves no keyboardShortcut it can rewrite, so it is safe to run twice. To print the rewrites first, pass --dry-run to the mantle command, or leave out --update-all from the ast-grep command. Run your formatter after the rewrite.
You are an agent migrating a codebase. Do this:
- Search for
keyboardShortcutonQuery.Input, through theQueryimport from@ngrok/mantle/queryand any alias of it (import { Query as MantleQuery }). LeavekeyboardShortcutonCommand.DialogRootandSidebar.Rootalone: those props stay. - Where the value is
keyboardShortcutorkeyboardShortcut={true}, remove the prop and wrap the field:FocusShortcut.Rootoutside, thenFocusShortcut.Field, then theQuery.Input.<FocusShortcut.Hint />as the first child ofQuery.Input, before any inline actions.import { FocusShortcut } from "@ngrok/mantle/focus-shortcut";
- Remove
keyboardShortcut={false}. The shortcut was off by default. - Where a component forwards its own boolean (
keyboardShortcut={keyboardShortcut}), choose one:- Keep the component's prop, and render the wrapped field from step 2 when it is true and the plain field when it is false. A change of the value at runtime then remounts the field, which loses focus and selection, so set it once per page.
- Or remove the component's prop, and let each caller wrap the field. This is the better shape when the component already takes the field as a child.
- In tests: the hint's
data-slotchanges.- Before:
document.querySelector('[data-slot~="query-input-shortcut"]') - After:
document.querySelector('[data-slot~="focus-shortcut-hint"]') - Where the field has the shortcut, the hint now stays in the DOM with the
hiddenattribute while it does not show. Replaceexpect(hint).toBeNull()withexpect(hint).not.toBeVisible(). Where the field has no shortcut, keepexpect(hint).toBeNull().
- Before:
- Run your formatter, linter, type checker, and tests.
Why a component and not a prop? The
/shortcut is not specific toQuery: a plainInput, aCombobox.Input, and aTextAreaneed it too, and a prop on each field is four copies of one behavior. A part also lets the hint go where the design puts it, such as beside a bareCombobox.Input.
Before → after
A literal shortcut
Inline actions
A forwarded value
Edge cases & gotchas
FocusShortcut.Rootrenders no element, so the wrap does not change the layout. It can go higher in the tree when the hint sits outside the field.- A caller's own
aria-keyshortcutson the field stays.FocusShortcut.Fieldadds/to the list. - Step 5 covers the test changes.
How to verify
- Run the type checker. A
keyboardShortcutleft onQuery.Inputis a type error. - Load a page with the field, click outside it, and press
/. Focus moves into the field, and the/hint hides. - Run your tests after step 5.