initial commit
This commit is contained in:
24
src/pages/ctrlK.js
Normal file
24
src/pages/ctrlK.js
Normal file
@@ -0,0 +1,24 @@
|
||||
import React, { useRef, useEffect } from 'react';
|
||||
|
||||
const CtrlK = () => {
|
||||
useEffect(() => {
|
||||
const handleKeyPress = (event) => {
|
||||
if (event.key === 'k' && (event.metaKey || event.ctrlKey)) {
|
||||
event.preventDefault();
|
||||
textFieldRef.current.focus();
|
||||
}
|
||||
|
||||
if (event.key === 'Escape' && document.activeElement === textFieldRef.current) {
|
||||
textFieldRef.current.blur();
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('keydown', handleKeyPress);
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyPress);
|
||||
};
|
||||
}, [textFieldRef]);
|
||||
};
|
||||
|
||||
export default CtrlK;
|
||||
Reference in New Issue
Block a user