Skip to content

Add designer hotkey disable, remapping, and imperative actions - #27

Merged
ashalugin merged 15 commits into
masterfrom
23-feature-add-designer-hotkey-disable-remapping-and-imperative-actions
Nov 27, 2026
Merged

ashalugin merged 15 commits into
masterfrom
23-feature-add-designer-hotkey-disable-remapping-and-imperative-actions

Conversation

@cherepanov

Copy link
Copy Markdown
Contributor

Summary

  • Add FormBuilderProps.hotkeys to disable all designer global shortcuts or remap/disable individual actions for embedding hosts.
  • Expand IFormBuilder with imperative deleteSelected, cloneSelected, save, print, undo, and redo so hosts can register external hotkeys.
  • Move print coordination to features/print and document embedding usage.
  • Closes [Feature] Add designer hotkey disable, remapping, and imperative actions #23

Packages affected

  • @react-form-builder/designer

Checklist

  • I followed CONTRIBUTION.md and CONTRIBUTING.md
  • I ran npm run check-all locally (or explain why not)
  • Tests updated/added under tests/ when appropriate
  • Docs updated under documentation/docs for user-facing changes
  • External contributors: I have signed the CLA (comment the sign phrase on this PR if CI asks)

Breaking changes / migration

None.

@cherepanov cherepanov added this to the 12.2.0 milestone Nov 26, 2026
@cherepanov cherepanov self-assigned this Nov 26, 2026
@cherepanov
cherepanov marked this pull request as ready for review November 26, 2026 11:25
@cherepanov
cherepanov requested a review from ashalugin November 26, 2026 11:25
@cherepanov cherepanov added the feature New feature or request label Nov 26, 2026

@ashalugin ashalugin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this revision with Node 26.13.1 and npm 11.21.2. The full static gate, module suite, and component suites on React 18 and 19 passed. Additional checks reproduced the issues in the inline comments.

Comment thread packages/designer/src/FormBuilder.tsx Outdated
const GlobalHotkeys = ({children}: {children: ReactNode}) => {
const builderStore = useBuilderStore()
const handleKeyDown = useHotkeys()
const hotkeysDisabled = builderStore.props.hotkeys === false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply hotkey changes after mount

Mount with default hotkeys, then rerender the same FormBuilder with hotkeys={false}. With focus on the page body, the designer still prevents both Ctrl/Cmd+S and Ctrl/Cmd+P and calls window.print(). Starting with false and rerendering with bindings: {print: {key: 'F8'}} leaves F8 inactive. The store keeps its initial props for the lifetime of the component. Read the current hotkeys prop for listener registration and binding resolution so a host can take over without remounting the designer.

if (binding === false || binding === undefined) continue
const list = Array.isArray(binding) ? binding : [binding]
for (const hotkey of list) {
result.push([hotkey, action])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle conflicting chords before dispatch

Set bindings: {print: {key: 'Delete'}}, select a field, and dispatch a Delete keydown with focus on the page body. The selected field is removed and Print never runs. The default Delete binding appears before the override, and the handler uses the first match. Please detect conflicting chords or define explicit precedence so a configured Print shortcut cannot silently delete a field.

hotkeys={{
bindings: {
// Replace only Save’s default Ctrl/Cmd+S chord; Delete, duplicate, print, undo, redo stay default
save: {key: 's', alt: true},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a Save example that works on macOS

On the macOS US layout, Option+S produces ß (U+00DF). I verified the native keyboard translation and confirmed that dispatching a keydown with key: 'ß' and altKey: true leaves Save untouched. A non-character chord such as F8 avoids the layout-dependent character in this example. KeyboardEvent.key values

BuilderStore keeps mount-time props, so toggling hotkeys after mount
had no effect. Provide the live hotkeys prop through React context for
listener registration and binding resolution.
When Print was bound to Delete, the default Delete binding still matched
first and removed the selection. Drop conflicting default chords and
prefer overrides in the resolved list.
Hard-coded Ctrl/Cmd+P stayed visible when print was disabled or remapped.
Show the resolved print chord, or omit the hint when there is none.
Option+S is layout-dependent on macOS US (produces ß), so the example
could not trigger Save. Prefer a non-character chord.
…gner-hotkey-disable-remapping-and-imperative-actions
Assert Preview/Edit mode after deferred print flush so disabled-hotkey
checks cannot false-pass, cover live remap and Ctrl/Cmd+S, prove Delete
override keeps the selection, and guard formatHotkeyShortcut navigator.
React 18 treated the license/SearchForm updates from that pattern as
console errors under vitest-fail-on-console.
@cherepanov
cherepanov requested a review from ashalugin November 27, 2026 07:42
@ashalugin

Copy link
Copy Markdown
Collaborator

Tested a650316f locally on React 18 and 19. One runtime defect reproduced in Chromium on both versions.

The Print shortcut can delete a field. Use the following binding order.

hotkeys={{bindings: {deleteSelected: {key: 'F8'}, print: {key: 'F8'}}}}

The Print menu displays F8. Select a field, move focus to the page body, and press F8. The field is deleted and window.print() is never called. Keyboard dispatch takes the first matching chord, while the Print menu still advertises the shadowed binding.

TypeScript compatibility. Existing custom implementations and mocks of IFormBuilder need all six new methods. A mock that compiled against master failed with TS2740 on this PR.

npm run check-all passed, along with 313 module tests and 2,592 component tests. The focused Chromium run passed 19 of 20 cases per React version, including all six imperative actions through both builderRef and useFormBuilder. The print tests stubbed window.print().

@cherepanov

cherepanov commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed in 146eeb1 duplicate chord conflicts (e.g. deleteSelected and print both on F8) are now detected so a shadowed Print binding can no longer delete a field. @ashalugin

@ashalugin
ashalugin merged commit 9de33ab into master Nov 27, 2026
7 checks passed
@ashalugin
ashalugin deleted the 23-feature-add-designer-hotkey-disable-remapping-and-imperative-actions branch November 27, 2026 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add designer hotkey disable, remapping, and imperative actions

2 participants