Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 8c14384

Browse files
Hubert KosterHubert Koster
authored andcommitted
chore: refactoring
1 parent 5bb97de commit 8c14384

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/components/SearchButton/index.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ const SearchButton = ({ setToggleSearch, toggle_search }: TSearchButton) => {
1414
const press_escape = event.key === 'Escape';
1515
const press_cmd_and_k = event.metaKey && event.key === 'k';
1616

17-
if (press_escape) setToggleSearch(false);
18-
if (press_cmd_and_k) setToggleSearch(false);
17+
if (press_escape || press_cmd_and_k) {
18+
setToggleSearch(false);
19+
}
1920
};
2021

2122
const openSearchHotkey = (event) => {
2223
const press_cmd_and_k = event.metaKey && event.key === 'k';
23-
if (press_cmd_and_k) setToggleSearch(true);
24+
25+
if (press_cmd_and_k) {
26+
setToggleSearch(true);
27+
}
2428
};
2529

2630
const focusSearchInput = () => {
2731
// Using vanilla JS to get the element since it's a 3rd party library. I cannot access through React.
28-
const search_input = document.querySelector('.navbar__search-input');
32+
const search_input = document.querySelector('.navbar__search-input') as HTMLFormElement;
2933
if (search_input) {
30-
const focusInput = () => (search_input as HTMLElement).focus();
34+
const focusInput = () => search_input.focus();
3135
focusInput();
3236
}
3337
};

0 commit comments

Comments
 (0)