DocSearch provides built-in keyboard shortcuts to enhance the search experience. You can enable, disable, or customize these shortcuts to match your site’s needs.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/algolia/docsearch/llms.txt
Use this file to discover all available pages before exploring further.
Default Shortcuts
DocSearch comes with two default keyboard shortcuts:Cmd+K / Ctrl+K
Opens and closes the search modal. This is the most common shortcut pattern used across documentation sites.
/ (Forward Slash)
Opens the search modal. This shortcut only opens the modal (doesn’t close it) and is ignored when typing in input fields.
Configuration
Configure keyboard shortcuts using thekeyboardShortcuts prop:
Disabling Shortcuts
You can disable specific shortcuts by setting them tofalse:
Even when all shortcuts are disabled, the Escape key will still close the modal. This ensures users always have a way to dismiss the search interface.
How Shortcuts Work
Cmd+K / Ctrl+K
TheCtrl/Cmd+K shortcut automatically detects the user’s operating system:
- macOS: Triggers on
Cmd+K(⌘ K) - Windows/Linux: Triggers on
Ctrl+K
metaKey (Cmd on Mac) or ctrlKey (Ctrl on Windows/Linux):
Forward Slash (/)
The forward slash shortcut only opens the modal and does not close it. It’s designed to be non-intrusive:- Ignored in input fields: The shortcut won’t trigger when typing in
<input>,<textarea>,<select>, orcontentEditableelements - Character-based: Since
/is a typeable character, it only opens the modal (doesn’t toggle)
Ask AI Integration
When using the Ask AI feature, there’s an additional behavior:- Escape in Ask AI mode: If the search modal is open with Ask AI active, pressing Escape first exits Ask AI mode and returns to regular search
- Second Escape press: Closes the modal entirely
Usage Examples
Only Allow Cmd+K
If you want to prevent the/ shortcut (perhaps it conflicts with your site’s routing):
Only Allow Forward Slash
If you want to reserveCmd+K for another feature:
Button-Only Activation
Disable all keyboard shortcuts to only allow opening via the search button:Implementation Details
The keyboard shortcuts system is implemented using a custom React hook calleduseDocSearchKeyboardEvents. Here’s how it works:
Event Listener Setup
Default Configuration
The default keyboard shortcuts are defined in constants:TypeScript Interface
The keyboard shortcuts configuration uses the following TypeScript interface:Best Practices
Keep defaults when possible
The default shortcuts (
Cmd+K and /) are familiar to most users from other documentation sites. Only disable them if they conflict with existing functionality.Communicate changes
If you disable or change the default shortcuts, make sure to update your documentation and any keyboard shortcut hints in your UI.
Test across platforms
Remember that
Cmd+K becomes Ctrl+K on Windows/Linux. Test your configuration on different operating systems.