-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add save shortcut for navigation menu screen (#21342)
* Add save shortcut for navigation menu screen * Remove option that is not an option * Update package lock to reflect new keyboard shortcuts dependency
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/edit-navigation/src/components/menu-editor/shortcuts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEffect, useCallback } from '@wordpress/element'; | ||
import { useDispatch } from '@wordpress/data'; | ||
import { useShortcut } from '@wordpress/keyboard-shortcuts'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
function MenuEditorShortcuts( { saveBlocks } ) { | ||
useShortcut( | ||
'core/edit-navigation/save-menu', | ||
useCallback( ( event ) => { | ||
event.preventDefault(); | ||
saveBlocks(); | ||
} ), | ||
{ | ||
bindGlobal: true, | ||
} | ||
); | ||
|
||
return null; | ||
} | ||
|
||
function RegisterMenuEditorShortcuts() { | ||
const { registerShortcut } = useDispatch( 'core/keyboard-shortcuts' ); | ||
useEffect( () => { | ||
registerShortcut( { | ||
name: 'core/edit-navigation/save-menu', | ||
category: 'global', | ||
description: __( 'Save the menu currently being edited.' ), | ||
keyCombination: { | ||
modifier: 'primary', | ||
character: 's', | ||
}, | ||
} ); | ||
}, [ registerShortcut ] ); | ||
|
||
return null; | ||
} | ||
|
||
MenuEditorShortcuts.Register = RegisterMenuEditorShortcuts; | ||
|
||
export default MenuEditorShortcuts; |