Focus Shortcut
Lets the slash key (/) move focus into one field from anywhere on the page, and shows a / hint where you place it. It wraps any focusable field: Input, InputCapture, TextArea, Combobox.Input, or Query.Input.
When to use
- Let
/focus the one primary filter or text box on a page, and show a/hint beside it. - Prefer
Kbdto show a key in copy or a tooltip, with no shortcut behind it. - Prefer
Commandfor a⌘Kpalette that runs an action or navigates.
Query
Wrap Query.Input in FocusShortcut.Field, and pass FocusShortcut.Hint as a child of Query.Input. The hint then sits at the field's right edge, before any inline actions.
projectFilterGrammar and projects are the ones from the Query page.
Combobox
Combobox.Input renders its own chrome and takes no children, so you place the hint. FocusShortcut.Root renders no element, so it can hold a wrapper that positions the hint over the field.
Composition
Polymorphism
FocusShortcut.Hint takes asChild. Use it to draw the hint with your own element, such as a muted <span> in a dense toolbar. The hint keeps aria-hidden, translate="no", and the hidden attribute that shows and hides it.
FocusShortcut.Field always merges onto its one child, so it needs no asChild.
Inside Field.Control, put FocusShortcut.Root outside the control and FocusShortcut.Field inside it, around the field. The id, name, and ARIA that Field.Item owns then reach the field, and the field still names / in its aria-keyshortcuts.
Behavior
/still types a slash while focus is in any text control, including one inside an open shadow root. On a checkbox, a radio, or a button,/moves focus to the field./does nothing with Meta, Ctrl, or Alt held, while an IME composes, or on a key repeat.- A field that is disabled (natively, by a
fieldset, or witharia-disabledon it or a group around it), not displayed, or behind a modal (inertoraria-hidden="true"on an ancestor) does not take the key. The key then goes to the next field with the shortcut. - When two fields have the shortcut,
/goes to the field that mounted first and can take focus. Give the shortcut to one field per page. - The hint follows typing, focus,
disabled, and a controlledvalue. When your code sets the field'svalueproperty directly, dispatch aninputevent so the hint updates. - To let a user turn the shortcut off, such as from a keyboard-shortcuts setting, render the field without
FocusShortcut.Rootwhile the setting is off. - A listener that calls
preventDefault()on the key first keeps the key.FocusShortcut.FieldcallspreventDefault()when it takes the key, so the slash does not type into the field.
Accessibility
FocusShortcut.Fieldadds/to the field'saria-keyshortcuts, and keeps the shortcuts you set on its direct child. PutFocusShortcut.Fielddirectly around the element that takes focus, such as theInputCaptureinside anInput, and set other shortcuts on that element.FocusShortcut.Hintisaria-hidden, becausearia-keyshortcutsnames the key to assistive tech.- A device that cannot hover, such as a phone, usually has no key to press, so the hint does not show there. The shortcut stays.
API Reference
FocusShortcut.Root
Connects one FocusShortcut.Field to its FocusShortcut.Hint. It renders no element.
FocusShortcut.Field
Makes / move focus into its child. It renders no element of its own, and merges its props onto the child. The child's ref must reach the element that takes focus.
FocusShortcut.Hint
The / key, rendered as a Kbd. It accepts every kbd prop except children, hidden, and translate.