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:
parent
2039f1ac92
commit
6b08ad5978
1 changed files with 13 additions and 0 deletions
|
@ -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={{
|
||||||
|
|
Loading…
Add table
Reference in a new issue