# profile-builder/4.0.0/form-builder/blocks/src/components/DisableKeyboardShortcuts.js

User Profile Builder – Beautiful User Registration Forms, User Profiles &amp; User Role Editor, version 4.0.0. 70 lines.

- Page: https://pluginprobe.com/plugins/profile-builder/4.0.0/code/form-builder/blocks/src/components/DisableKeyboardShortcuts.js
- Raw: https://pluginprobe.com/plugins/profile-builder/4.0.0/raw/form-builder/blocks/src/components/DisableKeyboardShortcuts.js
- Modified: 2026-08-17T08:51:38+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/profile-builder/4.0.0/code/form-builder/blocks/src/components/DisableKeyboardShortcuts.js#L10-L20`.

```javascript
/**
 * Unregister all Gutenberg keyboard shortcuts on PB form CPTs.
 * On-screen controls keep working; only key bindings go.
 *
 * Scope: `core/keyboard-shortcuts` only. RichText formatting is internal and
 * stays. Sweep categories via `getCategoryShortcuts` (no "all names" selector);
 * re-unsubscribe on store changes until empty.
 */

import { useEffect } from '@wordpress/element';
import { useSelect, select as dataSelect, dispatch as dataDispatch, subscribe } from '@wordpress/data';
import { registerPlugin } from '@wordpress/plugins';

const PB_CPTS = [ 'wppb-rf-cpt', 'wppb-epf-cpt' ];
const STORE = 'core/keyboard-shortcuts';

// Core categories plus headroom; unknown categories return [].
const SWEEP_CATEGORIES = [
    'global', 'block', 'main', 'list-view',
    'text', 'canvas', 'editor', 'register', 'selection', 'navigation',
];

const collectShortcutNames = () => {
    const sel = dataSelect( STORE );
    if ( ! sel || typeof sel.getCategoryShortcuts !== 'function' ) return [];
    const names = new Set();
    for ( const category of SWEEP_CATEGORIES ) {
        let list;
        try { list = sel.getCategoryShortcuts( category ); } catch ( e ) { continue; }
        if ( Array.isArray( list ) ) {
            list.forEach( ( name ) => { if ( name ) names.add( name ); } );
        }
    }
    return Array.from( names );
};

// Only dispatches for names that exist — empty store → no loop.
const unregisterAllShortcuts = () => {
    const dis = dataDispatch( STORE );
    if ( ! dis || typeof dis.unregisterShortcut !== 'function' ) return 0;
    const names = collectShortcutNames();
    names.forEach( ( name ) => dis.unregisterShortcut( name ) );
    return names.length;
};

const DisableKeyboardShortcuts = () => {
    const postType = useSelect(
        ( select ) => select( 'core/editor' ).getCurrentPostType(),
        []
    );
    const isOurPostType = PB_CPTS.includes( postType );

    useEffect( () => {
        if ( ! isOurPostType ) return undefined;

        unregisterAllShortcuts();

        // Core may register after us or on remount; re-sweep until empty.
        const unsubscribe = subscribe( () => {
            unregisterAllShortcuts();
        }, STORE );

        return unsubscribe;
    }, [ isOurPostType ] );

    return null;
};

registerPlugin( 'wppb-fb-disable-keyboard-shortcuts', { render: DisableKeyboardShortcuts } );

```
