saveShortcut
Why JS.
import { saveShortcut } from "@sdxc/ui/app";Usage
Applied to any element in or beside a form: ⌘S (Ctrl+S elsewhere) submits that form through
requestSubmit, while typing included. With several bound forms on a page, the one holding
focus saves; with focus outside them all, the only bound form saves.
Signature
saveShortcut(options?: SaveShortcuts.Options): MixinDescriptor<HTMLElement>Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options | SaveShortcuts.Options | No |
Examples
<span hidden mix={[saveShortcut({ form: "post-form" })]} />Used with it
The events, constants and types its module publishes, each imported from @sdxc/ui/app too.
Constant
SAVE_SHORTCUT
The keys that save, as the shortcut registry spells them.
const SAVE_SHORTCUT = "mod+s"Function
bindSaveShortcut
Binds ⌘S to binding.form until signal aborts, through the page's shortcut registry. Every
binding on the page agrees on one form per keystroke, so exactly one saves; a keystroke that
chooses none is still held back from the browser's save-page dialog.
bindSaveShortcut(binding: SaveShortcuts.Binding, signal: AbortSignal): void| Parameter | Type | Required | Description |
|---|---|---|---|
binding | SaveShortcuts.Binding | Yes | The form and how it saves. |
signal | AbortSignal | Yes | Removes the binding. |
Interface
SaveShortcuts.Options
Configuration for saveShortcut.
| Member | Type | Required | Description |
|---|---|---|---|
form | string | No | The id of the form ⌘S submits; omit to submit the form the host sits in. |
Interface
SaveShortcuts.Binding
One form's answer to ⌘S.
| Member | Type | Required | Description |
|---|---|---|---|
form | HTMLFormElement | Yes | |
save | void | Yes | Saves the form once ⌘S chose it. |
fallback | boolean | No | Yields to every other binding of the same form, so a save bar steps aside for the form's own primary save and one keystroke submits once. |