feat: Add a keyboard shortcut to move focus to search (#4796)

Fixes: #4700
Signed-off-by: Chetan Banavikalmutt <chetanrns1997@gmail.com>
This commit is contained in:
Chetan Banavikalmutt 2020-12-01 23:04:52 +05:30 committed by GitHub
parent 6e1649b1e2
commit 6095fc564f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -165,6 +165,19 @@ export const ApplicationsList = (props: RouteComponentProps<{}>) => {
const [isAppCreatePending, setAppCreatePending] = React.useState(false);
const searchBar = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
const handleKeyPress = (e: KeyboardEvent) => {
if (e.keyCode === 47 && searchBar.current && !appInput) {
searchBar.current.querySelector('input').focus();
e.preventDefault();
}
};
document.addEventListener('keypress', handleKeyPress);
return () => {
document.removeEventListener('keypress', handleKeyPress);
};
});
const loaderRef = React.useRef<DataLoader>();
function refreshApp(appName: string) {
// app refreshing might be done too quickly so that UI might miss it due to event batching