ShortcutGuide
Description
The "keyboard shortcuts" sheet, listing an app's shortcuts in titled sections and optionally answering them
ShortcutGuide is the sheet an app opens from its help menu or with Ctrl+/: a Modal whose content is a list of sections, each row a description on the left and its keys on the right, drawn by KeyboardShortcut. It takes the same key names KeyboardShortcut.Matches tests, so a shortcut is declared once and what is listed cannot drift from what is bound.
Usage
Section(title) starts a section — every shortcut added after it is listed under it, until the next Section(...); pass null or empty for an untitled one. Shortcut(description, params keys) adds a row, with key names such as "Ctrl", "Shift", "Enter", "Escape" and "ArrowUp", so modifiers show as ⌘/⇧ on macOS and Ctrl/Shift elsewhere. Describe what the shortcut does ("Quick chat or search"), not what the command is called in the code.
OnPressed(action) gives the shortcut added last something to do. A row without one is listed but not answered, which is right when the key belongs to some other component. Handle(KeyboardEvent) runs the first listed shortcut the event matches and returns whether one did, so the caller stops the event only when the press was taken:
window.addEventListener("keydown", ev =>
{
if (guide.Handle(ev.As<KeyboardEvent>())) StopEvent(ev);
});
Show(), Hide(onHidden) and Toggle() drive the sheet, and IsVisible reads the state. ShowEmbedded() returns a component to place in a settings or help page instead of floating it. SetTitle(string), Width(UnitSize) (560px by default), LightDismiss() (on by default) / NoLightDismiss() and OnShow / OnHide configure the modal underneath, and the sizing helpers apply to it as they do on Modal.
Var(out var self) hands the guide to its own rows, which is how the Ctrl+/ entry both advertises and performs the toggle.
API reference
public sealed class ShortcutGuide : IComponent, ISpecialCaseStylingA modal listing an application's keyboard shortcuts, grouped into titled sections, each row a description on the left and the keys on the right as KeyboardShortcut chips. A shortcut is declared here with the same key names Matches tests, so a guide can also answer the presses it advertises: give an entry an action with OnPressed and call Handle from the application's keydown handler.
- Namespace
- Tesserae
- Implements
- IComponent, ISpecialCaseStyling
Constructors
| Name | Description |
|---|---|
| ShortcutGuide | Initializes a new instance of this class. |
Properties
| Name | Description |
|---|---|
| StylingContainer | Gets the styling container for the guide, so the sizing helpers reach the modal itself. |
| PropagateStylesToWrapper | Gets whether a sizing helper applied to this component should tag it so a wrapper-building container hoists the style onto the wrapper. |
| IsVisible | Gets a value indicating whether the guide is currently shown. |
public HTMLElement StylingContainerGets the styling container for the guide, so the sizing helpers reach the modal itself.
public bool PropagateStylesToWrapperGets whether a sizing helper applied to this component should tag it so a wrapper-building container hoists the style onto the wrapper.
Methods
| Name | Description |
|---|---|
| Section | Starts a new section. Every shortcut added after this call is listed under it, until the next Section. |
| Shortcut | Adds a shortcut to the current section, creating an untitled one if Section has not been called yet. |
| OnPressed | Sets the action the last added shortcut runs when Handle sees it pressed. A shortcut without one is listed but not answered - which is right when whatever owns the key already handles it. |
| Handle | Runs the action of the first listed shortcut that e matches, and answers whether one did - so a caller can stop the event only when the press was taken. |
| SetTitle | Sets the title of the component. |
| Width | Sets the width of the component. |
| W | Sets the width of the component. |
| LightDismiss | Enables light-dismiss behaviour (clicking outside the guide closes it). It is on by default. |
| NoLightDismiss | Removes / disables the light dismiss on the component. |
| OnShow | Registers a callback invoked when the guide is shown. |
| OnHide | Registers a callback invoked when the guide is hidden. |
| Show | Shows the component. |
| Hide | Hides the component. |
| Toggle | Shows the guide if it is hidden and hides it if it is shown, which is what the shortcut that opens it usually does. |
| ShowEmbedded | Returns the guide as a component to place in the page, instead of showing it as a modal layer. |
| Render | Renders the component's root HTML element. |
public ShortcutGuide Section(string title)Starts a new section. Every shortcut added after this call is listed under it, until the next Section.
Parameters
- title
- The section's title, e.g. "General". Pass null or empty for an untitled section.
public ShortcutGuide Shortcut(string description, params string[] keys)Adds a shortcut to the current section, creating an untitled one if Section has not been called yet.
Parameters
- description
- What the shortcut does, e.g. "Quick chat or search".
- keys
- The keys, in the names
KeyboardShortcuttakes, e.g. "Ctrl", "K".
public ShortcutGuide OnPressed(Action action)Sets the action the last added shortcut runs when Handle sees it pressed. A shortcut without one is listed but not answered - which is right when whatever owns the key already handles it.
public bool Handle(KeyboardEvent e)Runs the action of the first listed shortcut that e matches, and answers whether one did - so a caller can stop the event only when the press was taken.
public ShortcutGuide SetTitle(string title)Sets the title of the component.
public ShortcutGuide LightDismiss()Enables light-dismiss behaviour (clicking outside the guide closes it). It is on by default.
public ShortcutGuide NoLightDismiss()Removes / disables the light dismiss on the component.
public ShortcutGuide OnShow(Modal.OnShowHandler onShow)Registers a callback invoked when the guide is shown.
public ShortcutGuide OnHide(Modal.OnHideHandler onHide)Registers a callback invoked when the guide is hidden.
public ShortcutGuide Toggle()Shows the guide if it is hidden and hides it if it is shown, which is what the shortcut that opens it usually does.
public IComponent ShowEmbedded()Returns the guide as a component to place in the page, instead of showing it as a modal layer.
See also
- Keyboard Shortcut — the key chips, and
Matches - Modal — the surface underneath
- Command Palette — the Ctrl/Cmd-K launcher a guide usually lists
- Sidebar —
SidebarButton.SetKeyboardShortcut(...) - Component catalog