0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Added keyboard shortcut to open search modal

refs https://github.com/TryGhost/Team/issues/1665

- adds cmd/ctrl + K shortcut to open the search modal on page
This commit is contained in:
Rishabh 2022-07-06 15:05:31 +02:00
parent 2039f1ac92
commit 6b08ad5978

View file

@ -30,11 +30,13 @@ export default class App extends React.Component {
componentWillUnmount() { componentWillUnmount() {
/**Clear timeouts and event listeners on unmount */ /**Clear timeouts and event listeners on unmount */
window.removeEventListener('hashchange', this.hashHandler, false); window.removeEventListener('hashchange', this.hashHandler, false);
window.removeEventListener('keydown', this.handleKeyDown, false);
} }
initSetup() { initSetup() {
// Listen to preview mode changes // Listen to preview mode changes
this.handleSearchUrl(); this.handleSearchUrl();
this.addKeyboardShortcuts();
this.hashHandler = () => { this.hashHandler = () => {
this.handleSearchUrl(); this.handleSearchUrl();
}; };
@ -51,6 +53,17 @@ export default class App extends React.Component {
} }
} }
addKeyboardShortcuts() {
this.handleKeyDown = (e) => {
if (e.keyCode === 75 && e.metaKey) {
this.setState({
showPopup: true
});
}
};
document.addEventListener('keydown', this.handleKeyDown);
}
render() { render() {
return ( return (
<AppContext.Provider value={{ <AppContext.Provider value={{